471,120 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

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
Apr 12 '08 #1
2 2496
nateraaaa
663 Expert 512MB
Which version of the .NET framework are you using?

Nathan
Apr 14 '08 #2
Plater
7,872 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. MailMessage m = new MailMessage("from@me", "to@me", "this is the subject", "File(s) attached");
  2. m.Attachments.Add(Attachment.CreateAttachmentFromString("here is a text attachment", "text/plain"));
  3. m.Attachments.Add(Attachment.CreateAttachmentFromString("and another text attachment", "text/plain"));
  4. m.Attachments.Add(Attachment.CreateAttachmentFromString("still more text attachments", "text/plain"));
  5. m.Attachments.Add(Attachment.CreateAttachmentFromString("and another text attachment", "text/plain"));
  6. for (int i = 0; i < 10; i++)
  7. {
  8.     Attachment a = new Attachment("mypic" + i.ToString() + ".jpg", "image/jpeg");
  9.     m.Attachments.Add(a);
  10. }
  11.  
Apr 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Roy G. Vervoort | last post: by
5 posts views Thread by Olivier/Noetika | last post: by
2 posts views Thread by Malik Asif Joyia | last post: by
6 posts views Thread by Anuradha | last post: by
6 posts views Thread by electroon | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.