我已在Azure网络应用中配置了我的应用。我正在使用smtp服务器发送邮件。前景是正确发送电子邮件。其他邮件提供商(Gmail)不发送电子邮件。请帮忙。
答案 0 :(得分:0)
Other mail providers like(Gmail) are not sending emails You could check the providers that have policy to allow to do that.
Take gmail for example, as Ankit Kumar mentioned that you need to turn Allow less secure apps: on for your gmail account.
我也在我这边测试,它工作正常。以下是我的演示代码。
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Tom Gmail", "xx@gmail.com"));
message.To.Add(new MailboxAddress("Tom Hotmail", "xxx@hotmail.com"));
message.Subject = "I am a mail subject";
message.Body = new TextPart("plain")
{
Text = "I am a mail body."
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate("sunguiguan@gmail.com", "@WSX3edc");
client.Send(message);
client.Disconnect(true);
}
我们也可以在Azure上使用SendGrid,更多细节请参考How to Send Email Using SendGrid with Azure.