【发布时间】:2011-02-18 16:36:40
【问题描述】:
我正在尝试使用 C# 发送电子邮件。我们的电子邮件提供商建议我使用mail.example.com/exchange 而不是mail.example.com
string mailServer;
mailServer = "mail.example.com";
mailServer = "mail.example.com/exchange";
SmtpClient smtpClient = new SmtpClient(mailServer);
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new NetworkCredential("username", "password");
smtpClient.Send("from@example.com", "to@foo.com", "subj", "email body");
当mailServer 不包含目录时,经过长时间的停顿,我得到:
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 连接尝试失败,因为连接方在一段时间后没有正确响应,或建立连接失败,因为连接的主机没有响应
当mailServer 确实包含一个目录时,完全没有停顿,我得到:
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法解析远程名称:'mail.example.com/exchange'
如何使用 C# 为包含目录的 FQDN 发送电子邮件?
【问题讨论】: