asp.net core 郵件發送
由於core不帶smpt
所以借助MimeKit
以163郵箱為例
var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("王大昭", "[email protected]"));
message.To.Add(new MailboxAddress("王昭", "[email protected]"));
message.To.Add(new MailboxAddress("楊西西", "[email protected]"));
message.Subject = "本周工作報告";
TextPart body = new TextPart(TextFormat.Html)
{
Text = "發一下本周工作報表 "
};
using (SmtpClient client = new SmtpClient())
{
//Smtp服務器
client.Connect("smtp.163.com", 25, false);
//登錄,發送
//特別說明,對於服務器端的中文相應,Exception中有編碼問題,顯示亂碼了
client.Authenticate("註冊的郵箱", "授權驗證碼");
client.Send(message);
//斷開
client.Disconnect(true);
Console.WriteLine("發送郵件成功");
}
asp.net core 郵件發送