How do I use the Attachment and AttachmentCollection class together with the MailMessage. On MailMessage there's an readonly property "Attachments", but how can i set it?

purpose: new messages locally created in a different format that should be uploaded to imap server

asked 04 Mar '11, 14:58

martin's gravatar image

martin
745
accept rate: 0%


Use the Add method of Attachments collection as in following code:

// create a mail message and add attachment to it
MailMessage message = new MailMessage()
message.Attachments.Add(new Attachment("c:\\data.zip"));

Following code will fill values for some basic properties and will upload the message to the server via IMAP:

message.From        = "from@example.org";
message.To          = "to@example.org";
message.Subject     = "Mail subject";

Imap client = new Imap();
client.Connect("imap.example.org");
client.Login("username", "password");    

// upload the message into Inbox  
client.StoreMessage("Inbox", mail);

You may also find following tutorials handy:

link

answered 04 Mar '11, 21:07

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×53
×10

Asked: 04 Mar '11, 14:58

Seen: 721 times

Last updated: 01 Apr '11, 21:22