关闭传输错误.等待来自客户端的数据超时



我使用本地主机通过SES发送批量邮件。很多人都回答了这个问题,但没有一个解决方案对我有帮助。问题是我可以一次发送100/150封邮件,之后出现上述错误。我试着按照一些人的建议处理客户端,但没有成功。我使用c#代码来做到这一点。任何回答/建议都是非常感谢的。下面是我使用for循环发送批量邮件的代码。你可能会认为这可能是一个节流问题,这不是因为我们每秒有70封邮件,每天有50万封邮件。

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 !!";

最新更新