[英]The SMTP server requires a secure connection or the client was not authenticated. Error while sending outlook mail using c# webapplication
I'm not sure about which mailServer
should be using for microsoft.com mail.我不确定应该为 microsoft.com 邮件使用哪个
mailServer
。
This is my code:这是我的代码:
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);
You should use port 587, see POP and IMAP email settings for Outlook .您应该使用端口 587,请参阅Outlook 的 POP 和 IMAP email 设置。
SmtpClient smtpCl = new SmtpClient("smtp-mail.outlook.com", 587);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.