使用System.Net.Mail在公司外部收不到发送邮件

Sending emails are not received outside the company using System.Net.Mail

我正在使用以下代码发送电子邮件。工作中的收件人已成功收到电子邮件,但在外部收不到。我试图向我的 gmail 帐户发送电子邮件,但同样的问题,我无法收到。 在工作中,我们使用的是 Exchange 2010。我在 gmail 中检查了垃圾邮件,但没有找到任何电子邮件。

我的代码:

    public bool SendEmail()
    {
        try
        {
            var mailMessage = CreateMailMessage();

            var client = new SmtpClient()
            {
                Credentials = new NetworkCredential(Resources.Username, Resources.Password, Resources.Domain),
                Port = 25,                    
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Host = ConfigurationProperties.ExchangeIPAddress
            };

            client.Send(mailMessage);
        }
        catch (Exception ex)
        {
            LogFile.Write(string.Format("EmailManager::SendEmail failed at {0}", DateTime.Now.ToLongTimeString()));
            LogFile.Write(string.Format("Error: {0}", ex.Message));
            return false;
        }

        return true;
    }

    private MailMessage CreateMailMessage()
    {
        var mailMessage = new MailMessage();

        mailMessage.Subject = ConfigurationProperties.EmailSubject;
        mailMessage.Body = ConfigurationProperties.EmailBody;
        mailMessage.IsBodyHtml = true;
        mailMessage.BodyEncoding = Encoding.UTF8;
        mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

        LogFile.Write(string.Format("Subject= {0}", mailMessage.Subject));
        LogFile.Write(string.Format("Body= {0}", mailMessage.Body));

        AddRecipients(mailMessage);

        return mailMessage;
    }

为了让外部电子邮件收件人接收电子邮件,我是否遗漏了任何属性?

没有 属性 可以设置为允许邮件发送到您的网络之外。这听起来像是您的 Exchange 服务器上的配置,与 System.Net.Mail.

无关

您需要与系统管理员联系。