【问题标题】:Random "Index was outside the bounds of the array" as an SmtpException随机“索引超出数组范围”作为 SmtpException
【发布时间】:2012-03-14 14:15:34
【问题描述】:

我使用如下所示的 Send 方法随机遇到异常。我得到的例外是:

Exception information:
    Exception type: System.Net.Mail.SmtpException
    Exception message: Failure sending mail.

Inner exception information (level 1):
    Exception type: System.IndexOutOfRangeException
    Exception message: Index was outside the bounds of the array.

我的方法如下所示:

public void Send(string from, List<string> to, string subject, string body, List<string> attachments)
{
    var email = new MailMessage();
    var server = new SmtpClient();

    // Add each mail property
    email.From = new MailAddress(from);
    foreach (var t in to)
        email.To.Add(t);
    email.Subject = subject;
    email.IsBodyHtml = true;
    email.Body = body;
    foreach (var a in attachments)
        email.Attachments.Add(new Attachment(a));
    server.Send(email);
}

在调用此覆盖之前,我正在验证收件人列表和附件列表都至少有一个值并且该值有效。

异常发生在sever.Send上。

【问题讨论】:

标签: c# email smtpclient system.net.mail


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2018-09-03
    • 2014-09-09
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多