我尝试将SMTP设置从C#移动到XML。我偶然发现了设置网络凭证,请参阅最后一行。 XML中的正确语法是什么?
using (var smtp = new SmtpClient())
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(md.From, "password");
await smtp.SendMailAsync(msg);
}
web.config
文件中的SMTP旧版本设置:
<mailSettings>
<smtp from="From@gmail.com">
<network host="smtp.gmail.com" port="587" userName="From@gmail.com"
password="*******" enableSsl="true" />
</smtp>
</mailSettings>