簡體   English   中英

使用System.Net.Mail在公​​司外部未收到發送電子郵件

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

我正在使用以下代碼來發送電子郵件。 電子郵件在工作中已成功接收到收件人,但未在外部接收。 我試圖將電子郵件發送到我的gmail帳戶,但同樣的問題,但我收不到。 在工作中,我們使用的是Exchange2010。我檢查了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無關。

您需要與系統管理員聯系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM