简体   繁体   中英

Send Multiple email at same time with different body using webmail

I am using WebMail in mvc5 and i have a condition now to send emails to multiple user and each user's email body will be different from other . If i send them using loop then it will take to much time to return back to View . So , whats the best solution in this case ?

Here is my code to send a single email

 WebMail.SmtpServer = "smtp";
        WebMail.SmtpPort = 25;
        WebMail.UserName = "myemail";
        WebMail.From = "senderemail";
        WebMail.Password = "mypassword";
        WebMail.Send(to,
            "subject",
            "body");

Something like this would be the fastest so you're only setting the non-specific stuff once. You're effectively sending different emails, if body was the same i'd use bcc or cc.

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);
  });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM