提问人:user3570063 提问时间:11/17/2022 最后编辑:Eugene Astafievuser3570063 更新时间:11/19/2022 访问量:704
asp.net c# Web 窗体使用 Outlook 365 发送电子邮件
asp.net c# Web Forms send email using outlook 365
问:
这是我的公司切换到 Outlook 365 之前本地计算机的代码: SmtpClient SMTP 客户端 = new SmtpClient(ConfigurationManager.AppSettings[“EMailServer”]); smtpClient.Send(消息);
由于前景已更改,我谷歌并找到此代码,但是它不起作用,给出错误代码“无法发送电子邮件”“一般失败”。 请帮我解决这个问题 下面是一个新代码:
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredentmailial("email address", "network password");
client.Port = 25; // You can use Port 25 if 587 is blocked (mine is!)
client.Host = "smtp.office365.com";
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.TargetName = "STARTTLS/smtp.office365.com";
client.Send(message);
谢谢。 维塔利。
答:
0赞
Abdul Haseeb
11/19/2022
#1
这是我用来使用 HOST 发送电子邮件的代码 smtp.office365.com
var fromAddress = new MailAddress("[email protected]", "From Name");
var toAddress = new MailAddress("[email protected]", "To Name");
string fromPassword = "Your_email_password";
string subject = "Test Subject";
string body = "Test Message";
var smtp = new SmtpClient
{
Host = "smtp.office365.com",
Port = 25, //Recommended port is 587
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true
})
{
smtp.Send(message);
}
评论
EnableSsl
false
//client.DeliveryMethod = SmtpDeliveryMethod.Network;