gpt4 book ai didi

c# - 随机 "Index was outside the bounds of the array"作为 SmtpException

转载 作者:行者123 更新时间:2023-11-30 15:04:51 24 4
gpt4 key购买 nike

我使用如下所示的 Send 方法随机收到异常。我得到的异常(exception)是:

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# - 随机 "Index was outside the bounds of the array"作为 SmtpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9703675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com