c# - 关闭传输错误。等待客户端数据超时

标签 c# asp.net amazon-web-services amazon-ses

我正在使用本地主机通过 SES 发送批量邮件。许多人回答了这个问题,但没有一个解决方案对我有帮助。问题是在出现上述错误之后,我可以一次发送 100/150 封邮件。我试图按照某些人的建议处理客户,但没有奏效。我正在使用 C# 代码来执行此操作。非常感谢任何答案/建议。下面是我用来使用 for 循环发送批量邮件的代码。您可能会认为这可能是一个节流问题,这并不是因为我们有 70 封电子邮件/秒和每天 500000 封电子邮件。

Parallel.For(0, mail.Count, i =>
{
    // Replace with your "From" address. This address must be verified.
    String TO = mail; // Replace with a "To" address. If your account is still in the
    // sandbox, this address must be verified.

    // Create an SMTP client with the specified host name and port.
    using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(HOST, PORT))
    {
        // Create a network credential with your SMTP user name and password.
        client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);

        //Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then 
        //the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.
        client.EnableSsl = true;
        System.Net.Mail.MailMessage message1 = new System.Net.Mail.MailMessage(FROM, TO, SUBJECT, BODY);

        message1.IsBodyHtml = true;
        client.Send(message1);
        client.Dispose();
    }
});

最佳答案

我不知道它现在工作的确切原因,但它正在工作。我改变了上面代码的逻辑,它开始工作了。而不是每次都获取 SMTP 连接,为了发送每封邮件,这次我只获取了一次 smtp 连接并用它一次发送所有批量邮件并开始工作。但问题是发送时间,它是花了太多时间发送所有邮件。无论如何我也会找到解决方案。

using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(HOST, PORT))
{
    client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);
    client.EnableSsl = true;
    for(i=0;i<mail.Count;i++)
    {
        String TO = mail[i];
        System.Net.Mail.MailMessage message1 = new System.Net.Mail.MailMessage(FROM, TO, SUBJECT, BODY);

        message1.IsBodyHtml = true;

        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Send(message1);
    }

    client.Dispose();
}

Label1.Text = mail.Count.ToString() + " mails sent !!";

关于c# - 关闭传输错误。等待客户端数据超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31516746/

相关文章:

amazon-web-services - 使用 EKS 中的 Fluent Bit 在 AWS CloudWatch 中自动创建日志组

c# - 如何使用 ajax 调用将 formcollection 传递给一个 Action ?

c# - 限制打开的 nettcp 绑定(bind)连接

c# - 从日期 vb.net 计算耗时?

c# - 在 WPF 中调整网格内的 Canvas

asp.net - 使用 Jquery Mobile 和 ASP.NET MVC 3 Razor 下载文件

android - 亚马逊 AWS S3 文件上传。如何设置文件权限?

amazon-web-services - 仅当 lambda 发生任何更改时才使用 AWS Code Pipeline 执行云形成

javascript - 有没有办法以编程方式将 DIV 中的内容导出到图像?

c# - 使用第二个 UpdatePanel 的 gridview 中的 LinkBut​​ton 从第一个 UpdatePanel 更新文本框。找不到控件