3

我使用下面显示的 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 上。

4

1 回答 1

5

这听起来与发送带有大附件的电子邮件时有关 .NET 4.0 失败的问题相同。Microsoft 已在此处发布了一个错误修复程序

于 2012-03-14T14:30:09.437 回答