smtpclient.sendasync 无法处理太多收件人
该应用程序是使用 C# 的 WPF Windows 应用程序,
我正在尝试向相当长的收件人列表发送电子邮件。首先我要声明,这不是垃圾邮件,因为这些人已经注册了这个列表。
我正在使用 smtpclient.sendasync。当我将其发送给 1 到 3 个人时,这在测试中工作正常,但当我将其发送到整个邮件列表时,它无法工作。列表上的号码是2623。没有错误信息;只是收据没有收到电子邮件。这是一个需要调试的问题,因为我无法通过例如将其发送给 100 个人来测试它,因为这将是垃圾邮件。
请参阅下面的代码。请注意,我更改了电子邮件地址以防止垃圾邮件。
Int32 _MessageCount = 0;
MailMessage msg = new MailMessage();
SmtpClient client = new SmtpClient(Configuration.smtpServer);
string _PriorEMail = "";
msg.From = new MailAddress("[email protected]");
msg.To.Add (new MailAddress("[email protected]"));
// bcc to the list
foreach (string str in EmailToAddresses)
{
if (clsUtilities.IsAnEmail(str) == true && str != _PriorEMail)
{ // process only valid emails and avoid dups
_MessageCount += 1;
msg.Bcc.Add(new MailAddress(str));
_PriorEMail = str;
}
}
msg.Subject = EmailSubject;
msg.IsBodyHtml = true;
msg.Body = EmailBodyHtml;
client.SendAsync(msg,null);
This application is WPF Windows application using C#,
I am trying to send email to a fairly long list of recipients. Let me state at the outset that this is not spam as these people have signed up for this list.
I am using smtpclient.sendasync. This works fine in testing when I send it to 1 to 3 people but when I send it to the whole mailing list, it fails to work. The number on the list is 2623. There is no error message; it’s just that the receipts don’t get the email. This is a problem to debug because I can’t test it by, for example, sending it to 100 people because that would be spamming.
See the code below. Note I changed the email addresses to prevent spamming.
Int32 _MessageCount = 0;
MailMessage msg = new MailMessage();
SmtpClient client = new SmtpClient(Configuration.smtpServer);
string _PriorEMail = "";
msg.From = new MailAddress("[email protected]");
msg.To.Add (new MailAddress("[email protected]"));
// bcc to the list
foreach (string str in EmailToAddresses)
{
if (clsUtilities.IsAnEmail(str) == true && str != _PriorEMail)
{ // process only valid emails and avoid dups
_MessageCount += 1;
msg.Bcc.Add(new MailAddress(str));
_PriorEMail = str;
}
}
msg.Subject = EmailSubject;
msg.IsBodyHtml = true;
msg.Body = EmailBodyHtml;
client.SendAsync(msg,null);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该限制可能来自 SMTP 服务器本身:这些服务器的设置是为了防止出于各种原因(从法律到业务到性能)向大量收件人发送电子邮件。
请咨询 SMTP 服务器的提供商以了解实际限制。通过限制操作和/或使用允许更多收件人的 SMTP 服务器来解决此问题。
请参阅此 IIS文档 例如:它指出如果限制为 100,并且您的收件人列表为105 个地址长,仅处理前 100 个地址。
The limitation probably comes from the SMTP server itself: those are set-up to prevent sending emails to a huge amount of recipients, for various reasons (from legal through business to performance).
Check with the provider of the SMTP server for the actual limitation. Work around that by throttling the operation, and/or using an SMTP server which allows a greater number of recipients.
See this IIS documentation for example: it states that if the limit is 100, and your recipients list is 105 addresses long, only the first 100 addresses will be processed.
使用 SendAsync 向多个收件人发送电子邮件时,如果 SMTP 服务器接受某些收件人为有效收件人并拒绝其他收件人,则会引发 SmtpException 以及内部异常的 NullReferenceException。如果发生这种情况,SendAsync 将无法向任何收件人发送电子邮件。
Microsoft 网站
When sending e-mail using SendAsync to multiple recipients, if the SMTP server accepts some recipients as valid and rejects others, a SmtpException is thrown with a NullReferenceException for the inner exception. If this occurs, SendAsync fails to send e-mail to any of the recipients.
Microsoft Site