我试图通过SMTPS向我的应用程序发送电子邮件,System.Net不支持,但System.Web.Mail支持。 如果我发送带有一个附件的邮件它工作正常,但如果附件多于一个,我会收到无效附件的错误(当我调用新的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);
}