我是我的申请的网络邮件。我的帐户中没有收到邮件本地邮件可以正常工作,但网络邮件无法正常工作

时间:2019-03-29 10:47:22

标签: c# asp.net-web-api

我在我的应用程序中使用Web邮件,在appsetting.json文件中配置了一些凭据。我的问题是注册邮件没有到达。enter image description here

我不知道该怎么解决。

1 个答案:

答案 0 :(得分:0)

如果您使用gmail,则可以这样设置,并确保https://support.google.com/accounts/answer/6010255?hl=en-GBTurn On Access for less secure apps

using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}

更多参考,请访问Sending email in .NET through Gmail