3
我有一個關於在asp.net核心上發送電子郵件的問題。Asp.Net Core MailKit:根據驗證過程,遠程證書無效
所以我有這樣的代碼:
private void SendEmailLocalSMTP(string email, string subject, string message)
{
MimeMessage mailMsg = new MimeMessage();
//TESTING ENVIRONMENT ONLY!!!
mailMsg.To.Add(new MailboxAddress("[email protected]", "[email protected]"));
// From
mailMsg.From.Add(new MailboxAddress("[email protected]", "Facturacion"));
// Subject and multipart/alternative Body
mailMsg.Subject = subject;
string html = message;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("[email protected]", "myPassword");
// Init SmtpClient and send
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(credentials);
client.Send(mailMsg);
client.Disconnect(true);
}
}
從我在其他職位有點關係發現,這應該是足夠使用MailKit發送它,但它不能正常工作。我得到以下例外,我不知道如何從這裏開始。
這是例外:
我已經看到了這個問題,但我還沒有從中取得多大意義:How to send email by using MailKit?
任何幫助,高度讚賞,感謝。
謝謝!很好的答案! –