Dave Pruce

Dave Pruce

  • NA
  • 3
  • 2.7k

System.web.mail, CSharp, multiple attachments

Jan 6 2012 6:58 AM
Hi Guys
My first post so please be gentle.....
.Net4/VS2010/Our mail server
Mail without attachments gets sent fine
If I code like this:
  Attachment attachment = new System.Net.Mail.Attachment("c:\\mailattachments\\Test Mail Attachment.pdf");
  mailObj1.Attachments.Add(attachment);
  Attachment attachment1 = new System.Net.Mail.Attachment("c:\\mailattachments\\Test Mail Attachment2.pdf");
  mailObj1.Attachments.Add(attachment1);
  Attachment attachment2 = new System.Net.Mail.Attachment("c:\\mailattachments\\Test Mail Attachment3.pdf");
  mailObj1.Attachments.Add(attachment2);
Its fine and all 3 are attached

BUT, if I code like this (table has id's and file names from SQL, SomeList has the selected items): (like I should!!)
  for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  {
  for (int j = 0; j < SomeList.Count; j++)
  {
  if (ds.Tables[0].Rows[i][0].ToString() == SomeList[j].ToString())
  {
  Attachment attachment = new System.Net.Mail.Attachment("c:\\mailattachments\\" + ds.Tables[0].Rows[i][1].ToString());
  mailObj1.Attachments.Add(attachment);
  }
  }
  }
I get "Transaction failed. The server response was: Suspicious message" at the send.
Doesnt matter If I select 1 or more, the loop seems to do something to the message!
Can anyone help please
Cheers
Dave

Answers (1)