【问题标题】:Send Multiple email at same time with different body using webmail使用 webmail 以不同的正文同时发送多封电子邮件
【发布时间】:2014-02-20 19:31:35
【问题描述】:
我在 mvc5 中使用 WebMail,我现在有一个条件可以向多个用户发送电子邮件,并且每个用户的电子邮件正文将与其他用户不同。如果我使用循环发送它们,那么返回 View 需要很长时间。那么,在这种情况下,最好的解决方案是什么?
这是我发送一封电子邮件的代码
WebMail.SmtpServer = "smtp";
WebMail.SmtpPort = 25;
WebMail.UserName = "myemail";
WebMail.From = "senderemail";
WebMail.Password = "mypassword";
WebMail.Send(to,
"subject",
"body");
【问题讨论】:
标签:
c#
email
c#-4.0
smtp
webmail
【解决方案1】:
这样的事情会是最快的,所以你只设置一次非特定的东西。
您实际上是在发送不同的电子邮件,如果正文相同,我会使用密件抄送或抄送。
void Send(IDictionary<string, string> emailDetails, string subject)
{
WebMail.SmtpServer = ConfigHelper.SmtpServer;
WebMail.SmtpPort = ConfigHelper.SmtpPort;
WebMail.UserName = ConfigHelper.EmailUserName;
WebMail.From = ConfigHelper.EmailFrom;
WebMail.Password = ConfigHelper.Password;
emailDetails.ToList().ForEach( e =>
{
WebMail.Send(e.Key,
subject,
e.Value);
});
}