尝试通过Office 365发送电子邮件时的SMTP 5.7.57错误 [英] SMTP 5.7.57 error when trying to send email via Office 365

查看:1528
本文介绍了尝试通过Office 365发送电子邮件时的SMTP 5.7.57错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一些代码,以通过 Office发送电子邮件365的经过身份验证的SMTP服务:

I'm trying to set up some code to send email via Office 365's authenticated SMTP service:

var _mailServer = new SmtpClient();
_mailServer.UseDefaultCredentials = false;
_mailServer.Credentials = new NetworkCredential("test.user@mydomain.com", "password");
_mailServer.Host = "smtp.office365.com";
_mailServer.TargetName = "STARTTLS/smtp.office365.com"; // same behaviour if this lien is removed
_mailServer.Port = 587;
_mailServer.EnableSsl = true;

var eml = new MailMessage();
eml.Sender = new MailAddress("test.user@mydomain.com");
eml.From = eml.Sender;
eml.to = new MailAddress("test.recipient@anotherdomain.com");
eml.Subject = "Test message";
eml.Body = "Test message body";

_mailServer.Send(eml);

这似乎不起作用,我看到一个例外:

This doesn't appear to be working, and I'm seeing an exception:

SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.7.57 SMTP;客户端未通过身份验证以在MAIL FROM
期间发送匿名邮件 在System.Net.Mail.MailCommand.Send(SmtpConnection conn,Byte []命令,字符串从)中
在System.Net.Mail.SmtpTransport.SendMail处(MailAddress发件人,MailAddressCollection收件人,字符串deliveryNotify,SmtpFailedRecipientException&异常)
在System.Net.Mail.SmtpClient.Send(MailMessage消息)

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)

我已尝试启用网络跟踪,似乎建立了安全的通信(例如,我在日志中看到"STARTTLS"命令的一行,然后在日志中看到一行用户已验证远程证书有效".,并且以下Send()Receive()数据不能以纯文本格式读取,并且似乎不包含任何TLS/SSH恐慌)

I've tried enabling network tracing and it appears that secure communications are established (for example, I see a line in the log for the "STARTTLS" command, and later there's a line in the log "Remote certificate was verified as valid by the user.", and the following Send() and Receive() data is not readable as plain text, and doesn't appear to contain any TLS/SSH panics)

我可以使用相同的电子邮件地址和密码登录到 http://portal.office.com/并使用Outlook电子邮件Web邮件发送和阅读电子邮件,那么当以编程方式发送电子邮件时,可能导致身份验证失败的原因是什么?

I can use the very same email address and password to log on to http://portal.office.com/ and use the Outlook email web mail to send and read email, so what might be causing the authentication to fail when sending email programmatically?

有什么方法可以额外调试加密流吗?

Is there any way to additionally debug the encrypted stream?

推荐答案

在我遇到所有运气不佳的建议之后,我联系了Microsoft支持部门,他们的建议只是更改密码.

In my case after I tried all this suggestion without luck, I contacted Microsoft support, and their suggestion was to simply change the password.

这解决了我的问题.

请注意,密码没有过期,因为我成功登录了office365,但是重置解决了该问题.

Note that the password wasn't expired, because I logged on office365 with success, however the reset solved the issue.

经验教训:我不相信Office 365密码的过期日期,在我的情况下,密码将在1-2个月后过期,但无法正常工作. 这导致我开始调查我的代码,直到很长时间之后我才意识到问题出在损坏"或过早过期"的Office365密码中.

Lesson learned: don't trust the Office 365 password expiration date, in my case the password would be expired after 1-2 months, but it wasn't working. This leaded me to investigate in my code and only after a lot of time I realized that the problem was in the Office365 password that was "corrupted" or "prematurely expired".

不要忘记每3个月刷新"密码.

Don't forget every 3 months to "refresh" the password.

这篇关于尝试通过Office 365发送电子邮件时的SMTP 5.7.57错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆