System.Net.Mail.MailMessage / System.Net.Mail.SmtpClient发送重复的电子邮件

时间:2014-12-18 16:09:51

标签: c# .net email system.net.mail mailmessage

下面的代码使用System.Net.Mail.MailMessage / System.Net.Mail.SmtpClient来发送来自Windows 2008R2上IIS7上运行的ASP.NET / C#3.5SP1应用程序的文件。即使我们3年多没有更改代码,它最近也开始发送重复的电子邮件。例如,如果me@me.com是currentVendor.Email,则me @me.com会收到完全相同的2封电子邮件。有任何想法吗? Windows Update会导致这种情况吗?

Vendor currentVendor = Vendor.GetCurrent();
string POLocation = Vendor.GetPOLocation();
    #if !DEBUG
                                    MailMessage mailer = new MailMessage("orders@perks.com", "resdev@perks.com");
                                    string[] addresses = currentVendor.Email.Split(new char[] { ';', ',' });
                                    foreach (string recip in addresses)
                                    {
                                        mailer.To.Add(recip.Trim());
                                    }
    #else
                                MailMessage mailer = new MailMessage("orderstest@me.com", "devtest@me.com");
    #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);

提前致谢!

1 个答案:

答案 0 :(得分:0)

尝试检查此代码:

Vendor currentVendor = Vendor.GetCurrent();

不会返回重复的电子邮件地址?

只有一次调用MailClient.Send()方法:

mailClient.Send(mailer);

但请确保您没有多次调用已粘贴的整个代码段!