问题
Please do not mark it as a duplicate question because the solution exists for mail message, not for mailkit.
I am trying to send an email to multiple addresses. I tried using the code below but I have not tried using a loop.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("CUBES", from));
message.To.Add(new MailboxAddress("Not Reply", fcemail));
message.Cc.Add(new MailboxAddress("Maria",CC));
message.Subject = "Approval Required for Business Case";
using (var client = new SmtpClient())
{
try
{
client.Connect(host, port);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(user, password);
client.Send(message);
client.Disconnect(true);
}
catch (Exception ex)
{
ViewBag.error = ex.Message.ToString();
ViewData["Message"] = "msgx";
return View("NotFoundErrors");
}
}
回答1:
You can use AddRange method like this.
InternetAddressList list = new InternetAddressList();
list.Add(new MailboxAddress(emailaddress));
list.Add(new MailboxAddress(emailaddress));
list.Add(new MailboxAddress(emailaddress));
var message = new MimeMessage();
message.From.Add(new MailboxAddress("CUBES", from));
message.To.AddRange(list);
来源:https://stackoverflow.com/questions/53456619/send-a-single-email-to-multiple-recipients-using-mailkit-or-mimekit