簡體   English   中英

smtp 客戶端拋出錯誤消息操作已超時

[英]smtp client throwing error message operation has timed out

我正在使用帶有 office365 郵件服務器的 SmtpClient 來發送 email。 但是每次我嘗試 smtpclient.Send(msg) 時,它都會拋出 'Operation has timed out' smtpexception。 我已經嘗試了所有早期的選項,比如將端口更改為 587 並增加超時值,但沒有任何效果。 誰能幫我嗎。 下面是我的源代碼。

    using (MailMessage msg = new MailMessage
    {                    
        From = new MailAddress("Sender@ourdomain.com"),
        Subject = this.Subject,
        Body = this.Body,
        IsBodyHtml = true
    })
    {
        msg.To.Add(new MailAddress("Receiver@ourdomain.com"));
        using (SmtpClient client = new SmtpClient
        {
            Host = "smtp.office365.com",
            DeliveryMethod = SmtpDeliveryMethod.Network,
            EnableSsl = true,
            UseDefaultCredentials = false,                        
            Credentials = new System.Net.NetworkCredential("username", "password"),
            Port = 587
        })
        {
            try
            {
                client.TargetName = "STARTTLS/smtp.office365.com";
                client.Send(msg);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }

基本上,當您無法連接到 SMTP 服務器時,就會發生此問題,這就是超時發生的原因。 您收到此消息是因為超過了 100 秒的默認超時值。

可能有幾個問題導致此問題發生,即錯誤的 SMTP 地址、SMTP 拒絕、端口設置、SSL 配置等您需要修復。

暫無
暫無

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

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