问题描述
我有一个从网站发送电子邮件的简单方法:
I've got a simple method to send emails from the website:
... // local vars
using (var mail = new MailMessage(from, sendTo))
{
using (var smtp = new SmtpClient())
{
mail.CC.Add(cc);
mail.Bcc.Add(bcc.Replace(";", ","));
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = html == -1;
mail.Priority = priority;
mail.BodyEncoding = mail.SubjectEncoding = mail.HeadersEncoding = Encoding.UTF8;
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
try
{
if (mail.Body.IsNotEmpty())
{
smtp.Send(mail);
}
}
catch
{
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
if (mail.Body.IsNotEmpty())
{
smtp.Send(mail);
}
}
catch(Exception e)
{
// I log the error here
}
}
}
}
效果很好;但是,当发件人是 anything@domainname.com
而收件人是 bob@domainname.com
时,电子邮件会卡在 Drop
中inetpub/mailroot
目录的文件夹,并且从未发送给收件人.
Which works great; however, when the sender is anything@domainname.com
and the recipient is bob@domainname.com
, the emails are getting stuck in the Drop
folder of the inetpub/mailroot
directory and never sent to the recipient.
问题是 - 我怎样才能解决这个问题,以便能够向同一(本地)域中的人发送电子邮件?
The question is - how I can get around this to be able to send emails to people on the same (local) domain?
推荐答案
我认为几乎可以肯定是邮件服务器配置问题.
I think it is almost certainly a mail server configuration issue.
根据 SmptClient.Send()文档 任何不正确的配置(主机、凭据、端口、SSL、防火墙、防病毒等)都应该抛出 InvalidOperationException
或 SmtpException
.
According to the SmptClient.Send() Documentation any incorrect configuration on your end (Host, Credentials, Port, SSL, Firewall, Anti-Virus etc) should throw an InvalidOperationException
or a SmtpException
.
您可以使用相同的代码和配置发送外部邮件这一事实 - 这意味着您可以连接到邮件服务器,这也非常强烈地表明问题出在下游.
The fact that you can send external mail using the same code and config - which means that you have connectivity to the mail server also very strongly suggests that the problem lies downstream.
我过去曾在有不同邮件服务器用于内部和外部邮件传递的公司工作.
I have worked at companies in the past that had different mail servers for internal and external mail delivery.
可能值得考虑消息使用的凭据.也许您有一个规则,它只允许一个组(所有公司或类似的东西)的成员向内部地址发送邮件.您可以通过使用您的真实域凭据来检查这一点(并在测试后将其删除)
It could be worth considering what Credentials are being used for the message. Perhaps you have a rule which only allows members of a group (All Company or something like that) to send mail to internals addresses. You could check this by using your real domain credentials (and removing them after the test)
smtp.Credentials = new NetworkCredential("your.username", "your.password");
无论哪种方式,如果没有产生异常,邮件应该已经在邮件服务器上接收到,并且由该服务器来决定传递.
Either way if no exception is generated the message should have been received on the mail server, and it is up to that server to determine delivery.
这篇关于向本地域发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!