0 votes
by (990 points)

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

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (13.0k points)
Best answer

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.Login("username", "password");    

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

You may also find following tutorials handy: