【发布时间】:2012-05-16 11:02:41
【问题描述】:
我写了一个控制台应用程序(只是站点代码的一部分,但它也必须分开工作,并且与站点内部的故障结果相同)(C#):
MailMessage message = new MailMessage("login@ourDomenInPunycode", "toMail")
{
Subject = "Hello",
Body = "Hello world"
};
SmtpClient client = new SmtpClient();
client.Host = "ourIP";
client.Credentials = new System.Net.NetworkCredential("login@ourDomenInPunycode", "ourPassword");
client.Port = 25;
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
那么,发送电子邮件不应该是小事吗?但是无论我通过我们的邮件服务器从本地机器发送邮件(只是运行这个控制台应用程序),都会出现以下异常:
System.Net.Mail.SmtpFailedRecipientException:邮箱不可用。服务器响应为:5.7.1 Relaying to denied (authentication required)
如果我将“login@ourDomenInPunycode”数据更改为我自己的邮箱(在 gmail 或其他邮箱 - 无论如何),一切正常。它也不依赖于“toMail”地址。
那么,我们的邮件服务器可能出了什么问题?有什么特殊设置吗?我们使用在另一个 Windows Server 2008 中虚拟化的 Windows Server 2008 和 Kerio Connect 7 作为虚拟 Windows Server 2008 上的邮件服务器。所有其他邮件程序(如 Outlook)都适用于从我们的邮件服务器发送电子邮件。
我在网上看到的所有关于SmtpClient设置的文章都只有这些(以上)琐碎的设置和代码,没什么特别的。
更新
我在上面的文字中做了一些修复。
当我尝试通过从邮件服务器虚拟 PC 启动的控制台应用程序发送邮件时,这是我们邮件服务器的一部分日志(上面的“ourIP”相关的“mail.ourDomen.local”):
Task 215 handler BEGIN
Task 215 handler starting
SMTP server session begin; client connected from mail.ourDomen.local:49399
Sent SMTP greeting to mail.ourDomen.local:49399
Command EHLO OurMailServer
Sent reply to EHLO: 250 mail.ourDomenInPunycode ...
Command MAIL FROM:<login@ourDomenInPunycode>
Sent reply to MAIL: 250 2.1.0 Sender <login@ourDomenInPunycode> ok
Command RCPT TO:<toMail>
Sent reply to RCPT: 550 5.7.1 Relaying to <toMail> denied
Connection to SMTP server mail.ourDomen.local lost: connection closed by remote host.
SMTP server session end
Task 215 handler END
“向 RCPT 发送回复:550 5.7.1 Relaying to denied” - 为什么会这样?
【问题讨论】:
标签: email smtpclient