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

0 votes
asked Mar 4, 2011 by martin (990 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,950 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:\\"));

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

message.From        = "";
message.To          = "";
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: