.net core 发送邮件
var message = new MimeMessage();
//发送方
message.From.Add(new MailboxAddress("liyy", "xxxxx.com"));
//接受方
message.To.Add(new MailboxAddress("Mrs. li", "xxxxx.com"));
//标题
message.Subject = "周末去哪嗨?";
//文字内容
message.Body = new TextPart("plain") { Text = "上海一日游" };
//开始发送
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
//发送方
message.From.Add(new MailboxAddress("liyy", "xxxxx.com"));
//接受方
message.To.Add(new MailboxAddress("Mrs. li", "xxxxx.com"));
//标题
message.Subject = "周末去哪嗨?";
//文字内容
message.Body = new TextPart("plain") { Text = "上海一日游" };
//开始发送
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.live.com", 465, true);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("发送方邮箱", "发送方邮箱Smtp授权码");
client.Send(message);
client.Disconnect(true);
}
client.Disconnect(true);
}