Skip to main content
 首页 » 编程设计

c#之使用包括目录的 FQDN 发送电子邮件

2024年02月23日36TianFang

我正在尝试使用 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: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

当 mailServer 确实包含一个目录时,完全没有停顿,我得到:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'mail.example.com/exchange'

如何使用 C# 为包含目录的 FQDN 发送电子邮件?

请您参考如下方法:

SMTP 不支持目录的概念,因此您可能需要一个知道他们在谈论什么的电子邮件提供商。