API
Version 7.x > API > Failed Emails in the Email Queue View modes: 
User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/14/2013 10:29:52 AM
   
Failed Emails in the Email Queue
We have several instances where emails fail and stay in the queue. The problem is the email is never sent again automatically, you have to manually click resend. I've also noticed if one fails, it causes a backlog and doesn't let others send because that particular one failed.

So I thought a good way to automate this would be to create a scheduled task that runs every 3-5 hours and simply resends the failed emails. The code was very simple although the process isn't working as expected. Here is my scheduled task method
protected void ResendFailedEmails(ref string result)
{
try
{
EmailHelper.Queue.SendAllFailed();
result = "Completed successfully.";
}
catch (Exception ex)
{
result = ex.Message;
}
}
Am I missing something? Is there another method that works better? Is there a way to get the details or code as to why an email is failing?

User avatar
Member
Member
kentico_sandroj - 6/14/2013 9:33:23 PM
   
RE:Failed Emails in the Email Queue
Hi FroggEye,

One of my colleagues can probably give you a better answer on which method should be used; however, I believe this article will help you troubleshoot in the meantime.

Regards,
Sandro

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/14/2013 9:53:02 PM
   
RE:Failed Emails in the Email Queue
Thanks Sandro, I did have the first key enabled
<add key="CMSLogEmails" value="true"/>
But it didn't help because it only logs to and subject. It would be ideal to have why it failed. Is it a mail server issue? Is it a configuration issue? Is it a recipient issue? When I send emails immediately, it works perfect but using the queue causes more headaches lately than I wish to deal with so any suggestions would be helpful.

One thing I do know is that if IIS is shut down and it restarts, the only way I can get the queue to process is to log in to either CMSDesk or CMSSiteManager.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/19/2013 2:41:19 PM
   
RE:Failed Emails in the Email Queue
So what I've come up with is we had port 25 blocked. After that was opened, we continued to have problems, sporadically. What we determined was the root of the problem is I had removed the SMTP server value from Site Manager>Settings>Global>System>E-Mails and populated the site specific value. Once I populated the global setting, any emails not coming specifically from a site were processed. Once I read the context help (again) I realized a default value needed to be in there, so I copied the same smtp server as in the site and all worked as expected.

User avatar
Member
Member
kentico_sandroj - 6/25/2013 4:46:17 PM
   
RE:Failed Emails in the Email Queue
Ah nice catch! Thank you for sharing the solution, I'm sure we'll find it helpful in the future.

Regards,
Sandro