Sending Multiple Attachement in a Mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sat1983
    New Member
    • Mar 2008
    • 1

    #1

    Sending Multiple Attachement in a Mail

    Hi

    I am beginner to C Sharp. trying to attach a multiple files to a mail.

    I can attach a single file or i can create multiple object of an Attachment class and add to a mail attachment object.

    But when i want to do it dynamically to attach multiple file...say my code might be generating one or more files depending on the result set...

    I have a temporary variable will keep track of no. of attachments and their path.

    Only problem I am facing is to add the files to attachment class dynamically...

    Any tips or an example in this will be of grt help to me....

    Thanks
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Which version of the .NET framework are you using?

    Nathan

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      So couldn't you just keep creating/adding attachments?
      I am not seeing what the problem is, you said you were able to add multiple attachment objects?

      Here is an email with 4 text attachments and 10 jpeg attachments
      Code:
      MailMessage m = new MailMessage("from@me", "to@me", "this is the subject", "File(s) attached");
      m.Attachments.Add(Attachment.CreateAttachmentFromString("here is a text attachment", "text/plain"));
      m.Attachments.Add(Attachment.CreateAttachmentFromString("and another text attachment", "text/plain"));
      m.Attachments.Add(Attachment.CreateAttachmentFromString("still more text attachments", "text/plain"));
      m.Attachments.Add(Attachment.CreateAttachmentFromString("and another text attachment", "text/plain"));
      for (int i = 0; i < 10; i++)
      {
      	Attachment a = new Attachment("mypic" + i.ToString() + ".jpg", "image/jpeg");
      	m.Attachments.Add(a);
      }

      Comment

      Working...