无法在asp.net C#中发送批量电子邮件
问题描述:
我无法一起发送批量电子邮件,但仍然没有使用foreach循环或其他循环.
请建议我是否可以一起发送大量电子邮件,需要使用foreach循环
我只能发送喜欢此...........
I m not able to send bulk emails together,still i am not using foreach loop or other Loop.
Please suggest me is it possible to send bulk emails alltogether or not ,Need to use foreach loop
i am only able to send LIKE THIS...........
MailMessage mailMessage = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
foreach (string EmailID in EmailAddress)
{
mailMessage = new MailMessage(FormEmailAddress, EmailID, Subject, MailMessage);
smtpClient = new SmtpClient();
mailMessage.IsBodyHtml = false;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential(FormEmailAddress, Password);
try
{
smtpClient.Send(mailMessage);
}
catch
{
}
finally
{
mailMessage = null;
smtpClient = null;
}
}
答
如果您想使用另一种发送批量电子邮件的方法,请尝试此链接.Automated-Email-Notifications-using-SQL-Server-Job-Schedular
manage-bulk-emails-aspnet
Try this link if you want to another approach to send bulk emails.
Automated-Email-Notifications-using-SQL-Server-Job-Schedular
manage-bulk-emails-aspnet
如果内容相同,那么为什么要发送n + 1次?
您只需在for循环中添加To地址即可.
If the content is same then why are you going for sending it n+1 times ?
You could simply add To address from your for loop.
MailMessage mailMessage = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
foreach (string EmailID in EmailAddress)
{
mailMessage.Bcc.Add(EmailID); /// see Bcc here
}
mailMessage.Subject = Subject;
mailMessage.From = new MailAddress(FormEmailAddress);
mailMessage.Body = mailMessage;
smtpClient = new SmtpClient();
mailMessage.IsBodyHtml = false;//upto you
smtpClient.UseDefaultCredentials = true; // required ?????
smtpClient.Credentials = new System.Net.NetworkCredential(FormEmailAddress, Password);
try
{
smtpClient.Send(mailMessage);
}
catch
{
}
finally
{
mailMessage = null;
smtpClient = null;
}