C# for loop可用于发送批量邮件、批量邮件问题、AWS(亚马逊)SES
我正在使用C#和.net进行编码,使用AWS(AMazon)SES(Simple Email Service)API一次性发送大约5000封邮件,如果发送的邮件数量小于500-600(大约),一切正常,但如果更像5000封,则会发送多达500-600封,然后停止发送电子邮件。我使用datatable存储数据库中的邮件列表,分配模板主体和主题,然后使用for循环逐个发送电子邮件。我需要知道这是编码问题还是for循环问题还是其他问题?有什么建议对我也有帮助吗C# for loop可用于发送批量邮件、批量邮件问题、AWS(亚马逊)SES,c#,asp.net,email,amazon-web-services,amazon-s3,C#,Asp.net,Email,Amazon Web Services,Amazon S3,我正在使用C#和.net进行编码,使用AWS(AMazon)SES(Simple Email Service)API一次性发送大约5000封邮件,如果发送的邮件数量小于500-600(大约),一切正常,但如果更像5000封,则会发送多达500-600封,然后停止发送电子邮件。我使用datatable存储数据库中的邮件列表,分配模板主体和主题,然后使用for循环逐个发送电子邮件。我需要知道这是编码问题还是for循环问题还是其他问题?有什么建议对我也有帮助吗 for (i = 0; i < d
for (i = 0; i < dtable1.Rows.Count; i++)
{
Object a=dtable1.Rows[i]["student_emailid"];
String TO1=Convert.ToString(a);
TO1 = TO1.Trim();
if (TO1.Equals("")) {
continue;
}
const String FROM = "asit@amcsquare.com"; // Replace with your "From" address. This address must be verified.
String TO = TO1; // Replace with a "To" address. If your account is still in the
// sandbox, this address must be verified.
String SUBJECT = email_subject;
String BODY = templateBody;
// Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
const String SMTP_USERNAME = "XXXXXXXXXXXX"; // Replace with your SMTP username.
const String SMTP_PASSWORD = "XXXXXXXXXXXXXXXXXX"; // Replace with your SMTP password.
// Amazon SES SMTP host name. This example uses the us-west-2 region.
const String HOST = "email-smtp.us-east-1.amazonaws.com";
// Port we will connect to on the Amazon SES SMTP endpoint. We are choosing port 587 because we will use
// STARTTLS to encrypt the connection.
const int PORT = 587;
// 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);
}
}
for(i=0;i
我不知道它现在起作用的确切原因,但它起作用了。我改变了上面代码的逻辑,它开始工作了。以前每次发送邮件时,我都没有获取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 !!";
使用(System.Net.Mail.SmtpClient client=new System.Net.Mail.SmtpClient(主机、端口))
{
client.Credentials=new System.Net.NetworkCredential(SMTP\u用户名、SMTP\u密码);
client.enablesl=true;
对于(i=0;i我不知道它现在工作的确切原因,但它正在工作。我更改了上述代码的逻辑,它开始工作。以前每次发送邮件时,我只提取了一次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 !!";
使用(System.Net.Mail.SmtpClient client=new System.Net.Mail.SmtpClient(主机、端口))
{
client.Credentials=new System.Net.NetworkCredential(SMTP\u用户名、SMTP\u密码);
client.enablesl=true;
对于(i=0;i您是否收到任何错误消息?亚马逊可能正在限制您的电子邮件。5000太多了,您很可能需要一个专门用于群发邮件的专用邮件服务器windows服务如何批处理?我现在已经检查了。我收到一个错误消息------Uncaught Sys.WebForms.PageRequestManagerTimeoutException:Sys、 WebForms.PageRequestManagerTimeoutException:服务器请求超时。您在SES上的发送配额是多少?您是否收到任何错误消息?Amazon可能正在限制您的电子邮件。5000太多了,您很可能需要专门用于群发邮件的专用邮件服务器windows服务如何逐批处理?我已经检查过了ed now.我收到一个错误消息-----未捕获Sys.WebForms.PageRequestManagerTimeoutException:Sys.WebForms.PageRequestManagerTimeoutException:服务器请求超时。您在SES上的发送配额是多少?