Trouble Sending Email To Office 365

主宰稳场 提交于 2020-01-05 09:36:28

问题


We are moving from a private Exchange server to Office 365. Previously, the following code worked:

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

From everything I've read, I should be able to do something like the following:

    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);

However, if I try to use port 587, I simply get a timeout. I cannot telnet to port 587 either (telnet smtp.office365.com 587). My own Outlook client is set up for https (port 443), and I can telnet to that port - but my code just returns "SMTP server returned an invalid response". Here's some sample code that I've tried:

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

Followed by any combination of:

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

Followed by smtp.Send(email);


回答1:


Check your firewall it might block the port.



来源:https://stackoverflow.com/questions/33522051/trouble-sending-email-to-office-365

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!