本文介绍了使用Mailkit或mimekit将一封电子邮件发送给多个收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请不要将其标记为重复的问题,因为存在针对邮件而不是针对邮包的解决方案.
我正在尝试将电子邮件发送到多个地址.我尝试使用下面的代码,但没有尝试使用循环.
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");
}
}
推荐答案
您可以使用这样的AddRange方法.
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);
这篇关于使用Mailkit或mimekit将一封电子邮件发送给多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!