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");
}
}
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With