应用程序发送电子邮件后出现两封空电子邮件的问题

发布于 2024-11-08 07:09:48 字数 920 浏览 0 评论 0原文

我的应用程序同时向收件人发送 3 封电子邮件,其中一封是正确的电子邮件,另外两封包含主题行,但为空消息。这段代码是如何导致的?如果不是,你有什么建议?

 var fromAddress = new MailAddress(domainAddress, displayName);
        var toAddress = new MailAddress(oInfo.SiteUser.email, oInfo.customerName);
        var Bcc = new MailAddress("deleted");
        var smtp = new SmtpClient
        {
            Host = SmtpHost(),
            Port = SmtpPort(),
            EnableSsl = true,

            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(SmtpUsername(), SmtpPassword())
        };

using (var msg = new MailMessage(fromAddress, toAddress)
        {
            IsBodyHtml = true,
            Subject = "Confirmation for your recent order at " + displayName,
            Body = body

        })
        {
            msg.Bcc.Add(Bcc);
            smtp.Send(msg);
        }

My app is sending 3 emails at the same time to the recipient, one being the correct email, and the other two contain the subject line, but an empty message. Could this code some how cause that? If not what do you suggest?

 var fromAddress = new MailAddress(domainAddress, displayName);
        var toAddress = new MailAddress(oInfo.SiteUser.email, oInfo.customerName);
        var Bcc = new MailAddress("deleted");
        var smtp = new SmtpClient
        {
            Host = SmtpHost(),
            Port = SmtpPort(),
            EnableSsl = true,

            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(SmtpUsername(), SmtpPassword())
        };

using (var msg = new MailMessage(fromAddress, toAddress)
        {
            IsBodyHtml = true,
            Subject = "Confirmation for your recent order at " + displayName,
            Body = body

        })
        {
            msg.Bcc.Add(Bcc);
            smtp.Send(msg);
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

快乐很简单 2024-11-15 07:09:50

不,该代码不会发送多于一封邮件。

要么您有更多代码用于发送邮件,要么您正在执行该代码三次,但正文的值不同。

No, that code won't send more than one mail.

Either you have some more code that is sending mail, or you are executing that code three times, but with different values for body.

灯角 2024-11-15 07:09:50

我能看到该代码的唯一问题是该行,

    var Bcc = new MailAddress("deleted");

但我假设您修改了它以便在此处发布?

我看不出会导致您所看到的问题。我会检查电子邮件的标题以获取线索。捕获发送电子邮件的计算机上的网络流量也可能有所帮助。

The only problem I can see with that code is the line

    var Bcc = new MailAddress("deleted");

but I assume you modified it for posting here?

I can't see an issue that would cause what you're seeing. I'd check the headers in the emails for clues. Also capturing network traffic on the machine sending the emails could help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文