关闭传输错误。超时等待来自客户端

时间:2015-07-20 12:38:37

标签: 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();
    }
});

1 个答案:

答案 0 :(得分:0)

我不知道它现在正在工作的确切原因,但它正在发挥作用。我改变了上面代码的逻辑,它开始工作了。为了每次都发送每封邮件,这次我只取了一次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 !!";