【问题标题】:System.Net.Mail.MailMessage/System.Net.Mail.SmtpClient Sending Duplicate EmailsSystem.Net.Mail.MailMessage/System.Net.Mail.SmtpClient 发送重复的电子邮件
【发布时间】:2015-02-17 11:55:20
【问题描述】:

下面的代码使用 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 会收到两封完全相同的单独电子邮件。有任何想法吗? Windows 更新会导致这种情况吗?

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);

提前致谢!

【问题讨论】:

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


    【解决方案1】:

    尝试检查是否有这段代码:

    Vendor currentVendor = Vendor.GetCurrent();
    

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

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

    mailClient.Send(mailer);
    

    但请确保不要多次调用已粘贴的整个代码 sn-p!

    【讨论】:

    • msporek,谢谢,但我确定邮件地址没有重复,而且我们只调用了一次 mailClient.Send(..)。
    猜你喜欢
    • 2012-08-09
    • 2013-10-23
    • 2020-04-24
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多