我知道这是一个老问题,但我可以为我的问题找到解决方案,这是事情,我试图通过smtp发送电子邮件的Outlook,但我收到此错误消息:SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应是:5.7.57 SMTP,对不起我的英文。
public void Send(MailMessage message)
{
msgToSend = message;
string password = string.Empty;
password = CryptoHelper.DecryptData("encoded_password", "key");
var smtpClient = new SmtpClient("smtp.office365.com", 587);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("username", "password");
smtpClient.EnableSsl = true;
smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
smtpClient.SendCompleted += (s, e) =>
{
smtpClient.Dispose();
message.Dispose();
};
smtpClient.SendAsync(message, null);
}