net core发邮件——MimeKit

   var message = new MimeMessage();
   message.From.Add(new MailboxAddress("谁发的", "发送方的邮件地址"));
   message.To.Add(new MailboxAddress("接收方", "接收方的邮件地址"));
   message.Subject = "主题";
   var bodyBuilder = new BodyBuilder();
   bodyBuilder.HtmlBody = "邮件内容";
   message.Body = bodyBuilder.ToMessageBody();
   using (var client = new SmtpClient())
   {
   //接受所有SSL证书(如果服务器支持SistTTLS)
   client.ServerCertificateValidationCallback = (s, c, h, e) => true;
   client.Connect("smtp.163.com", 0, false);
   client.Authenticate("发送方的账号", "发送方的密码");
   client.Send(message);
   client.Disconnect(true);
   }

最简单的发邮件

posted @ 2018-12-10 10:28  sunshuaize  阅读(456)  评论(0编辑  收藏  举报