无法向Office 365发送电子邮件

时间:2015-11-04 12:32:37

标签: c# .net smtp

我们正在从私有Exchange服务器迁移到Office 365.以前,以下代码有效:

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("Old Server Name");
smtp.Send(email);

从我读过的所有内容中,我应该可以执行以下操作:

    SmtpClient client = new SmtpClient();
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("your user name", "your password");
    client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
    client.Host = "smtp.office365.com";
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = true;
    client.Send(msg);

但是,如果我尝试使用端口587,我只是暂停。我也无法telnet到587端口(telnet smtp.office365.com 587)。我自己的Outlook客户端设置为https(端口443),我可以telnet到该端口 - 但我的代码只返回“SMTP服务器返回无效响应”。这是我尝试过的一些示例代码:

SmtpClient smtp = new SmtpClient("smtp.office365.com");
smtp.Port = 443;

随后是以下任意组合:

            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential("ID", "password");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.EnableSsl = true;
            smtp.TargetName = "STARTTLS/smtp.office365.com";

接着是smtp.Send(电子邮件);

1 个答案:

答案 0 :(得分:1)

检查您的防火墙,它可能会阻止该端口。