【发布时间】:2019-03-29 10:47:21
【问题描述】:
【问题讨论】:
-
需要代码而不是图像,还需要最少的示例来重现问题。
标签: c# asp.net-web-api
【问题讨论】:
标签: c# asp.net-web-api
如果您使用 gmail,您可以像这样设置并确保 Turn On Access for less secure apps by https://support.google.com/accounts/answer/6010255?hl=en-GB
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);
}
【讨论】: