发送电子邮件到本地域

发送电子邮件到本地域

本文介绍了发送电子邮件到本地域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种简单的方法可以从网站发送电子邮件:

  ...//本地变量使用(var mail = new MailMessage(from,sendTo)){使用(var smtp = new SmtpClient()){mail.CC.Add(cc);mail.Bcc.Add(bcc.Replace(;",,"));mail.Subject =主题;mail.Body =正文;mail.IsBodyHtml = html == -1;mail.Priority =优先级;mail.BodyEncoding = mail.SubjectEncoding = mail.HeadersEncoding = Encoding.UTF8;smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;尝试{如果(mail.Body.IsNotEmpty()){smtp.Send(邮件);}}抓住{smtp.DeliveryMethod = SmtpDeliveryMethod.Network;尝试{如果(mail.Body.IsNotEmpty()){smtp.Send(邮件);}}catch(异常e){//我在这里记录错误}}}} 

哪个作品很棒?但是,如果发件人为 [email protected] ,而收件人为 [email protected] ,则电子邮件将卡在 Drop inetpub/mailroot 目录的文件夹,并且永远不会发送给收件人.

问题是-如何解决这个问题,以便能够向相同(本地)域中的人发送电子邮件?

解决方案

我认为几乎可以肯定这是邮件服务器配置问题.

根据 SmptClient.Send()文档您端上的任何不正确配置(主机,凭据,端口,SSL,防火墙,防病毒等)都应抛出 InvalidOperationException SmtpException ./p>

您可以使用相同的代码和配置发送外部邮件的事实-这意味着您已连接到邮件服务器,这也非常有力地表明问题出在下游.

过去,我曾在拥有用于内部和外部邮件传递的不同邮件服务器的公司工作.

可能值得考虑正在使用什么证书的消息.也许您有一条规则,该规则仅允许组的成员(所有公司或类似公司)将邮件发送到内部地址.您可以使用您的真实域凭据进行检查(并在测试后将其删除)

  smtp.Credentials = new NetworkCredential("your.username","your.password"); 

无论哪种方式,如果都没有生成异常,则应该已经在邮件服务器上接收到该邮件,并且邮件的发送取决于该服务器.

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
            }
        }
    }
}

Which works great; however, when the sender is [email protected] and the recipient is [email protected], 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.

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.

这篇关于发送电子邮件到本地域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 14:10