繁体   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