For every e-mails that my website sends I have it send myself an email as well. I noticed that about 5% of the e-mails (Thousands a day) are being sent twice. The time between the duplicates being sent however is completely inconsistent...Can be a week, a month or a minute. Completely inconsistent...I've tried to debug the issue but I can never duplicate the issue. Always just sends one e-mail and works properly. I'm out of ideas so decided to try and gain some input form the community. Any insight would be greatly appreciated...
public static void SendEmail(string subject, string body, string toAddress, string fromAddress)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromAddress);
msg.To.Add(new MailAddress(toAddress));
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = false;
using (SmtpClient cli = new SmtpClient())
{
cli.Send(msg);
cli.Dispose();
}
}
Dispose() was just one of my recent attempts that have failed to fix the problem....
And the ascx page that calls the function (note that it is called twice to send it to myslef the first time and the customer the second time if there e-mail address is not null. I did this during testing and decided to leave it in there:
Txp.SendEmail(strOrderConfirmationHeader, strOrderConfirmationText, TxpConst.ORDERNOTIFYADDR, TxpConst.RETURNADDR);
if (!String.IsNullOrWhiteSpace(custemail))
{
Txp.SendEmail(strOrderConfirmationHeader, strOrderConfirmationText, custemail, TxpConst.RETURNADDR);
}
The fact that it's so inconsistent tells me it's probably not the code and it's not the e-mail server cause the mail logs show a completed transaction every time and it gets a different message id every time...I'm all out of ideas!