【问题标题】:Random System.Net.Mail.SmtpFailedRecipientsException exception - relay account office365随机 System.Net.Mail.SmtpFailedRecipientsException 异常 - 中继帐户 office365
【发布时间】:2016-02-16 23:42:31
【问题描述】:

我们有一个在 Windows Server 2008 机器上运行的应用程序。它使用 office365 smtp 中继帐户发送电子邮件。但是,并非所有电子邮件都发送成功。我们在 smtp.Send 调用发送的电子邮件中随机得到这两个异常:

  1. System.Net.Mail.SmtpFailedRecipientsException:无法发送给所有收件人。 ---> System.Net.Mail.SmtpFailedRecipientException:邮箱不可用。服务器响应为:5.7.64 TenantAttribution;中继访问被拒绝
  2. System.Net.Mail.SmtpFailedRecipientException:系统存储空间不足。服务器响应是:4.5.3 收件人太多

到目前为止,我们还无法弄清楚为什么会发生这种情况。任何想法都表示赞赏。

电子邮件代码使用 System.Net.Mail 命名空间 - .Net framework 4.0。 我们传入 NetworkCredential 的用户名和密码。

public void Send(string from, string[] to, string[] cc, string[] bcc, string subject, string body, string[] attachmentArr, Boolean isBodyHtml, string smtpServerName, int port = 25, bool enableSsl = true, string userName = null, string password = null, string domain = null, int timeoutMilliSec = 100000)
    {
        MailMessage objEmail = new MailMessage();

        try
        {
            foreach (string toItem in to)
            {
                objEmail.To.Add(toItem);
            }

            if (cc != null)
            {
                foreach (string toItem in cc)
                {
                    objEmail.CC.Add(toItem);
                }
            }

            if (bcc != null)
            {                    
                foreach (string toItem in bcc)
                {
                    objEmail.Bcc.Add(toItem);
                }
            }

            objEmail.From = new MailAddress(from);
            objEmail.Subject = subject;
            objEmail.Body = body;
            objEmail.IsBodyHtml = isBodyHtml;
            objEmail.Priority = MailPriority.High;

            if (attachmentArr != null)
            {
                foreach (String s1 in attachmentArr)
                {
                    objEmail.Attachments.Add(new Attachment(s1));
                }
            }

            using (SmtpClient smtp = new SmtpClient(smtpServerName))
            {
                if (string.IsNullOrEmpty(userName) == false && string.IsNullOrEmpty(password) == false)
                {
                    NetworkCredential credential = (string.IsNullOrEmpty(domain)) ? new NetworkCredential(userName, password) : new NetworkCredential(userName, password, domain);
                    smtp.Credentials = credential;
                }
                smtp.Timeout = timeoutMilliSec;
                smtp.Port = port;
                smtp.EnableSsl = enableSsl;

                smtp.Send(objEmail);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            if (attachmentArr != null && objEmail.Attachments != null)
            {
                foreach (Attachment a1 in objEmail.Attachments)
                {
                    a1.Dispose();
                }
            }
        }
    }

【问题讨论】:

    标签: smtp office365 system.net.mail


    【解决方案1】:

    我们终于找到了问题所在 - 电子邮件限制。 Office365 的 SMTP 客户端提交限制为每分钟 30 条消息https://technet.microsoft.com/en-us/library/dn554323%28v=exchg.150%29.aspx#summary 解决方案是每分钟发送少于 30 条消息。我认为它也受到服务器发送的其他消息(由 Outlook 发送)的影响。我们将消息之间的延迟降低到近五秒。从那以后,我们没有看到该错误再次发生。

    【讨论】:

      猜你喜欢
      • 2020-05-02
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2018-04-05
      • 1970-01-01
      相关资源
      最近更新 更多