System.web.mail only accepts one attachment

71 Views Asked by At

I'm trying to send an email with my application throug SMTPS, not supported by System.Net, but supported in System.Web.Mail. If I send the mail with one attachment it works fine, but if the attachment are more than one I get an error of Invalid Attachment (when I call the new MailAttachment(filename), not when i add it to the message). here is my code

        //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);

        }
0

There are 0 best solutions below