Post email notification failure: Newsletter Widget/SendMailMessageAsync

Jul 19, 2010 at 8:13 PM
Our site utilizes the newsletter widget to notify readers when there is a new post. There are 462 emails in the newsletter.xml file. I've set up a log for newsletter notification sends and failures. The log recorded only 7 sends from the latest post, which seems to match the feedback we are getting from readers. The log didn't record any sending errors. I've tested locally with a few names and the newsletter.xml file is being read correctly. Any clues on how to troubleshoot this issue other than logging? Has anyone seen this issue before? using BE 1.6 (latest version) Thanks, Rick static void Post_Saved(object sender, SavedEventArgs e) { Post post = (Post)sender; if (GetSendSendNewsletterEmails(post.Id)) { LoadEmails(); foreach (XmlNode node in _Doc.SelectNodes("emails/email")) { MailMessage mail = CreateEmail(post); mail.To.Add(node.InnerText); Utils.SendMailMessageAsync(mail); } } }
Coordinator
Jul 20, 2010 at 11:31 AM

For testing purposes only, you could try changing the code "SendMailMessageAsync" to "SendMailMessage" -- to see if all the emails go out.  This would make the sending process be synchronous, so when you create a new post, you will have to wait for all 462 emails to go out during the Save process.  I'm not suggesting you make this permanent (asynchronous is better), but just as a test to see if the asynchronous part of the process makes any difference.

Is it the first 7 or so people in the list that are getting the email, btw?  Or are they scattered throughout the list of emails?

There was an issue in BE 1.5, but that was fixed in 1.6.

Jul 20, 2010 at 2:11 PM
Hi Ben, Thanks for your reply. "SendMailMessage" was tested locally and 4 emails went out for each recipient (just two recipients on the local test) . The newsletter.xml file is getting read correctly and only one call is triggered in the loop that calls "SendMailMessage". I haven't gotten to the bottom of that yet. Our ISP suggested we change our server settings from the domain to localhost, so we are trying that as well. Thanks for the 1.5 pointer, it looks like our version is 1.6.0, I'll check the change log and code for any differences. I'll update this thread with more info as I get to the bottom of the "SendMailMessage" duplicates. Thanks, Rick
Jul 22, 2010 at 1:58 AM

Just finished a test with SendMailMessage instead of SendMailMessageAsynch and about 40% of the messages went out. We are using DiscountAsp.NET. No error messages from the SMTP server or BE. I'm kind of stumped.

Coordinator
Jul 22, 2010 at 12:20 PM

What kind of logging are you doing now?  Are you using the OnEmailSent and OnEmailFailed events that are raised within SendMailMessage (SendMailMessageAsync too)?  These events fire after every message is sent or failed to send.

In BE 1.6, there's a Utils.Log() function that you can log anything to.  The "Logger" extension in BE 1.6 will record the log data you send via Utils.Log() and put it in a file in the App_Data folder -- logger.txt.  You could log all of the OnEmailSent and OnEmailFailed events.  And you could also use Utils.Log() in the Newsletter widget's widget.ascx.cs file, logging each mail send attempt in the foreach loop (the loop that goes thru all the email addresses).

Jul 22, 2010 at 5:47 PM
Thanks again for your reply. OnEmailSent and OnEmailFailed are triggering the log. Out of the 474 emails, about 180 are logged as sent. There are no logs for any failures. The log isn't running inside the loop, but I'm pretty sure all the emails are getting read from the newsletter file. I'll add a count to the log to confirm that assumption. Testing with that many emails is a bit problematic so I'm trying to figure out a possible cause with as few tests as possible. I could try changing all the addresses to my address, but don't want to trigger any spam filters or reports.
Jul 22, 2010 at 9:40 PM
Edited Jul 22, 2010 at 9:41 PM
Is there a cache of the newsletter kept in memory? I just swapped out the newsletter.xml file with new addresses and it appears that the program used a cached version. Where is the StorageLoacation value set? #region StorageLocation /// <summary> /// Gets or sets the default storage location for blog data. /// </summary> /// <value>The default storage location for blog data.</value> public string StorageLocation { get; set; } #endregion
Jul 22, 2010 at 10:00 PM
OK, I see the StorageLocation value is set in the Web.Config and it is set correctly to the newsletter file directory. <add key="StorageLocation" value="~/App_Data/"/> How could a test send have used the old newsletter.xml data?
Coordinator
Jul 22, 2010 at 10:53 PM

Quite a bit of data, including the Newsletter data is cached in memory.  If you manually make changes to the Newsletter XML file, you can get BE to re-read that file by re-starting the BE application.  You can re-start the BE application by making any change to the web.config file in the root folder (add a space, etc.)

Jul 23, 2010 at 12:13 AM

There are a fairly small number of recipients, what if the check for the null value of the static variables in LoadEmails() was just removed?

    private static void LoadEmails()
    {
            _FileName = Path.Combine(BlogSettings.Instance.StorageLocation, "newsletter.xml");
            _FileName = System.Web.Hosting.HostingEnvironment.MapPath(_FileName);

            if (File.Exists(_FileName))
            {
                _Doc = new XmlDocument();
                _Doc.Load(_FileName);
            }
            else
            {
                _Doc = new XmlDocument();
                _Doc.LoadXml("<emails></emails>");
            }
    }