How to set attachment(s) on Rebex.Mail.MailMessage

0 votes
asked Mar 4, 2011 by martin (1,010 points)
edited Apr 1, 2011

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
answered Mar 4, 2011 by Martin Vobr (12,820 points)
edited Mar 4, 2011
 
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.Connect("imap.example.org");
client.Login("username", "password");    

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

You may also find following tutorials handy:

...