我能够在 Outlook 中设置一个 IMAP/SMTP 帐户,然后使用我们的内部 Zentyal 4.2 服务器发送一封测试电子邮件。然而,当我运行以下代码时,它会抛出 SmtpException。
var smtpClient = new SmtpClient("xyz.com");
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("my_account@xyz.com", "my_password");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
// TEST only
ServicePointManager.ServerCertificateValidationCallback =
delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; };
// end of TEST only
smtpClient.Send("my_account@xyz.com", "user2@anotherserver.com", "test", "test");
这是异常消息:
客户端无权向此服务器提交邮件。服务器响应为:4.7.1 user2@anotherserver.com:中继访问被拒绝。
我究竟做错了什么?