【问题标题】:The SMTP server requires a secure connection or the client was not authenticated. Error while sending outlook mail using c# webapplicationSMTP 服务器需要安全连接或客户端未通过身份验证。使用 c# webapplication 发送 Outlook 邮件时出错
【发布时间】:2021-04-12 06:55:36
【问题描述】:

我不确定应该将哪个 mailServer 用于 microsoft.com 邮件。
这是我的代码:

string toemail = "v-***@microsoft.com";
string subject =  "Testing Mail";
string mailBody = "<p>Hi..<br />This is testing email<br />Regards,<br />Nikita</p>";
// string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString(); 
string senderEmail = "v-****@microsoft.com";
string sendPwd = System.Configuration.ConfigurationManager.AppSettings["SenderPwd"].ToString();
SmtpClient smtpCl = new SmtpClient("smtp-mail.outlook.com", 25);
                smtpCl.EnableSsl = true;
smtpCl.Timeout = 1000000;
smtpCl.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpCl.UseDefaultCredentials = false;
smtpCl.Credentials = new NetworkCredential(senderEmail, sendPwd);

MailMessage mailMessage = new MailMessage(senderEmail, toemail, subject, mailBody);

mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = UTF8Encoding.UTF8;
smtpCl.Send(mailMessage);

【问题讨论】:

  • 端口 465 用于 ssl/tls
  • @Charlieface SmtpClient 仅支持 STARTTLS,不支持仅 SSL 端口上的 SMTP。所以我认为非 SSL 端口是正确的。
  • StartTLS 端口 587

标签: c# asp.net model-view-controller asp.net-core-webapi smtpclient


【解决方案1】:

您应该使用端口 587,请参阅POP and IMAP email settings for Outlook

SmtpClient smtpCl = new SmtpClient("smtp-mail.outlook.com", 587);

【讨论】:

  • 谢谢@iamdlm,它的工作。我已将其更改为 smtpClient smtpCl = new SmtpClient("smtp.office365.com", 587);但是我的发件人邮件服务器是:-microsoft.com,我无法检查 POP 和 smtp 设置。我可以知道,v-***@microsoft.com 的 smtp 服务器值
  • 同样在发件人邮件中,两因素身份验证已开启。
猜你喜欢
  • 2014-04-08
  • 2015-03-29
  • 2023-03-21
  • 2011-05-28
  • 1970-01-01
  • 2015-05-11
相关资源
最近更新 更多