Send a single email to multiple recipients using Mailkit or mimekit

前提是你 提交于 2020-06-25 22:52:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!