我正在尝试通过 SMTPS 与我的应用程序一起发送电子邮件,System.Net 不支持,但 System.Web.Mail 支持。如果我发送带有一个附件的邮件,它可以正常工作,但如果附件不止一个,我会收到 Invalid Attachment 的错误(当我调用新的 MailAttachment(文件名)时,而不是当我将其添加到邮件中时)。这是我的代码
//attachments is a List<> of FileInfo()
if (attachments != null)
{
List<MailAttachment> atts = new List<MailAttachment>();
foreach (FileInfo attachment in attachments)
{
try
{
atts.Add(new MailAttachment(attachment.FullName));
}
catch (Exception ex)
{
//error is in this try catch block, if attachments.Count > 1
string exc = ex.ToString();
MessageBox.Show(ex.ToString());
}
}
foreach(MailAttachment att in atts)
pec.Attachments.Add(att);
}