The code below uses System.Net.Mail.MailMessage/System.Net.Mail.SmtpClient to email files from a ASP.NET/C# 3.5SP1 application running on IIS7 on Windows 2008R2. Even though we haven't changed the code in 3+ years, it has recently started sending duplicate emails. For example, if [email protected] is the currentVendor.Email, [email protected] receives 2 separate emails exactly the same. Any ideas? Would a Windows Update have caused this?
Vendor currentVendor = Vendor.GetCurrent();
string POLocation = Vendor.GetPOLocation();
#if !DEBUG
MailMessage mailer = new MailMessage("[email protected]", "[email protected]");
string[] addresses = currentVendor.Email.Split(new char[] { ';', ',' });
foreach (string recip in addresses)
{
mailer.To.Add(recip.Trim());
}
#else
MailMessage mailer = new MailMessage("[email protected]", "[email protected]");
#endif
mailer.Subject = String.Format("{0} V2 Purchase Orders - {1}", currentVendor.Name, DateTime.Today.ToShortDateString());
mailer.IsBodyHtml = true;
mailer.Body = "Please find attached..... <br/>" +
"This email is system generated. If you have any trouble please, contact us";
mailer.Attachments.Add(new Attachment(POLocation));
SmtpClient mailClient = new SmtpClient();
mailClient.Send(mailer);
Thanks in advance!
Try to check if this code:
does not return duplicated email addresses?
There is only one call to MailClient.Send() method:
But make sure you don't call the entire code snippet which you have pasted more than once!