Code in charge of delivering mail

Topics: ASP.NET 2.0, Business Logic Layer
Dec 13, 2009 at 10:41 AM

Which is the file that is in charge to delivery the email once a comment has been added? I think it suffer the same problem I had found sometime ago with contact page.

Is it the file SendCommentMail.cs?

I tried to have a look at the Mail.Sender string and it's not there. The From field was a bit strange and I replaced it, but in any case it seems the function is not called at all, because I don't see any mail delivered once a comment has been added into the mail server log files.

Some help?

Coordinator
Dec 13, 2009 at 4:53 PM

SendCommentMail sends an email to the blog owner notifiying him a new comment has been left.

You're correct that contact.aspx was setting Mail.Sender which causes some problems.  SendCommentMail was not setting Sender, but setting the From address to the email address of the person leaving a comment.  This too can cause problems since some mail servers don't want to send email out when the From or Sender is not an email address managed by that email server -- and can be considered spoofing.

SendCommentMail was changed a little while back in one of the minor builds.  It now sets Mail.From to the email address of the blog owner (on the Settings tab):

mail.From = new MailAddress(BlogSettings.Instance.Email);

SendCommentMail also only sends out an email if the person leaving a comment is not logged into the blog.  So if you're logged in and leaving test comments, you won't get an email notification.

Also, on the Settings tab in the control panel, in the E-mail section, there's a setting labeled "Send comment e-mail".  I believe that needs to be checked in order for SendCommentMail to send you an email notification.

Lastly, make sure the SendCommentMail extension is Enabled on the Extensions tab.

Feb 16, 2010 at 10:18 PM
Edited Feb 16, 2010 at 10:19 PM
BenAmada wrote:

SendCommentMail also only sends out an email if the person leaving a comment is not logged into the blog.  So if you're logged in and leaving test comments, you won't get an email notification.

Ben, 

Thanks for the great information as always.  Discovering this about the new logged-in check saved me a lot of time in tracking this down.

I was wondering why this was added to 1.6 and what advantage it serves.  I'm essentially logged-in to my blogs around the clock, so this new logged-in check effectively disables comment emails.  How would a blog admin be notified of a new comment when authorized other than seeing it on a page reload if he or she was looking in the right spot?  I guess I'm saying that this change in 1.6 doesn't make any sense to me. :-)

Thanks,
Dave

 

Coordinator
Feb 16, 2010 at 10:45 PM

Hi Dave,

This behavior is not new in BE 1.6.  When I check the source code history for this SendCommentMail.cs file, it's been in there since at least July 2007.

SendCommentMail sends out an email to the blog owner when a new comment is left.  It's only the case when YOU are leaving the comment that the email notification is bypassed.  If a visitor is leaving a comment on the blog, they are not logged into the blog and so the comment notification email will be sent to the blog owner.

Hopefully this makes sense and we're on the same page ...

Feb 17, 2010 at 2:22 AM

Ben,

You're absolutely right, of course.  I went back to a site running 1.5 and found a note I left that explains my issue. I am requiring authentication through ASPNET Membership to post comments, so I couldn't pass

if (post != null && BlogSettings.Instance.SendMailOnComment && !Thread.CurrentPrincipal.Identity.IsAuthenticated)

I was being stupid.  Sorry for wasting you time, but I do appreciate the reply.

Thanks,
Dave

 

Coordinator
Feb 17, 2010 at 3:05 AM

No problem ... yes, that's the line of code in question.

If I too require authentication to post comments on my blog, I'm sure I'll get A LOT less spam!  :)