0
我正在使用ASP.Net Core并尝试使用Gmail中的smtp客户端发送电子邮件。有下面的代码,但它不工作 看过下面的帖子,以及,但它不工作 http://dotnetthoughts.net/how-to-send-emails-from-aspnet-core/通过gmail使用SMTP发送电子邮件
它thorws以下错误
System.NotSupportedException:SMTP服务器不支持身份验证
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("From Name", "[email protected]"));
emailMessage.To.Add(new MailboxAddress("To Name", "[email protected]"));
emailMessage.Subject = subject;
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = message;
emailMessage.Body = bodyBuilder.ToMessageBody();
var client = new SmtpClient();
try
{
await client.ConnectAsync("smtp.gmail.com", 25, SecureSocketOptions.None).ConfigureAwait(false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
await client.AuthenticateAsync("[email protected]", "fromPassword"); //error occurs here
await client.SendAsync(emailMessage).ConfigureAwait(false);
await client.DisconnectAsync(true);
await client.DisconnectAsync(true).ConfigureAwait(false);
}
catch(Exception e)
{
}
为什么在示例显示端口587时使用端口25? – mason
@mason点是正确的。我们可以使用587或465端口号在Gmail中使用smtp !.我不知道你为什么使用25。 – RajeeshMenoth