我正在使用asp.net c#发送Outlook电子邮件。
运行此命令时,我在(smtp.Send(fromAddress,toAddress,subject,body);)遇到错误,我在线搜索并尝试解决问题。请发送帮助。对此,我真的非常感激。
protected void btn_Click(object sender, EventArgs e)
{
string eml = "xxx@mymail.com";
var fromAddress = "xxx@outlook.com";
var toAddress = eml;
const string fromPassword = "password";
string subject = "Subject testing";
string body = "Welcome..";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");
{
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(fromPassword, fromPassword);
smtp.EnableSsl = true;
smtp.Credentials = credentials;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
答案 0 :(得分:2)
在线:
new System.Net.NetworkCredential(fromPassword, fromPassword)
两个参数都具有fromPassword,而不是用户名和密码
new System.Net.NetworkCredential(fromAddress, fromPassword)