我想通过交换服务器ie(outlook.office365.com,因为我可以从Outlook设置中看到它)使用SMTP从我的控制器(MVC4)发送电子邮件,但无法成功。我尝试了许多以前的帖子的解决方案,但无法得到任何线索。我衷心感谢所有帮助,从你们.. 这里是我的邮件配置:使用SMTP和交换服务器发送电子邮件时出错office365.com
<system.net>
<mailSettings>
<smtp>
<network host="smtp.office365.com" userName="[email protected]" password="defaultPassword"/>
</smtp>
</mailSettings>
</system.net>
这里是我的电子邮件类: 公共级电子邮件 { 公共电子邮件(){}
private string Sender{ get; set; }
private List<string> Recipients { get; set; }
private string Subject { get; set; }
private string Body { get; set; }
public bool SendEmail()
{
try
{
var smptClient = new SmtpClient { EnableSsl = true };
MailMessage newEmail = new MailMessage();
foreach (var reciepent in this.Recipients)
newEmail.To.Add(new MailAddress(recipient));
newEmail.From = new MailAddress(this.Sender);
newEmail.Subject = this.Subject;
newEmail.Body = this.Body;
newEmail.IsBodyHtml = false;
smptClient.Send(newEmail);
return true;
}
catch { return false; }
}
}
在上面的代码中,如果我使用“EnableSsl = true”,我得到错误“服务器不支持安全连接。”。如果我禁用SSL,我得到以下错误:
SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应是:5.7.57 SMTP;客户没有通过身份验证发送匿名邮件在邮件从
谢谢,但我已经试过这个。它导致像我在我的问题 –
中提到的相同的错误检查您使用的端口号。可能是您的端口被阻止 –
以前我使用过端口25,但是我收到错误“服务器不支持安全连接”。启用SSL,所以我用端口587,但它仍然无法工作 –