[英]ASP.NET Core Web API hosted on Azure don't send an email
I have an Web API based on ASP.NET Core and hosted on Azure as App Service.我有一个基于 ASP.NET 核心的 Web API 并作为服务托管在 Z3A580F142203677F1F0ZBC308 上。 I have a simple functionality for sending an email.
我有一个发送 email 的简单功能。 But it's only working on the localhost.
但它只适用于本地主机。 When I publish it on the Azure, the POST query returns me error: 500.
当我在 Azure 上发布它时,POST 查询返回错误:500。
It's a MailKit.Net.Smtp library.这是一个 MailKit.Net.Smtp 库。
{
[HttpPost]
[AllowAnonymous]
public async Task<ActionResult> SendMail([FromBody] Receiver receiver)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Step OSBB", "receiver@gmail.com"));
message.To.Add(new MailboxAddress("User name", receiver.Email));
message.Subject = "Henlo, it's a testing email";
message.Body = new TextPart("plain")
{
Text = "I am using MailKit to send this message"
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
client.Authenticate("myemail@gmail.com", "mypass");
client.Send(message);
client.Disconnect(true);
}
return StatusCode(200);
}
}
public class Receiver
{
public string Email { get; set; }
}```
Visit below link, and set Allow less secure app:Enabled
like me.访问下面的链接,并设置
Allow less secure app:Enabled
。 It works for me.这个对我有用。
https://www.google.com/settings/security/lesssecureapps https://www.google.com/settings/security/lesssecureapps
Related Post相关帖子
how to fix “send-mail: Authorization failed 534 5.7.14 ” 如何修复“发送邮件:授权失败 534 5.7.14”
Test steps:测试步骤:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.