[英]Forward client IP from ASP.NET Web API to .NET Core API hosted in Azure
[英]ASP.NET Core Web API hosted on Azure don't send an email
我有一個基於 ASP.NET 核心的 Web API 並作為服務托管在 Z3A580F142203677F1F0ZBC308 上。 我有一個發送 email 的簡單功能。 但它只適用於本地主機。 當我在 Azure 上發布它時,POST 查詢返回錯誤:500。
這是一個 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; }
}```
訪問下面的鏈接,並設置Allow less secure app:Enabled
。 這個對我有用。
https://www.google.com/settings/security/lesssecureapps
相關帖子
測試步驟:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.