Discuss this help topic in SecureBlackbox Forum

MIME: Create message with alternative parts

Below are the steps required to create a message with the alternate HTML + plain-text parts:

  1. Create an instance of TElMultiPartList class and set its sub-type to "alternative" using TElMultiPartList.ContentSubtype property;
  2. Create an instance of TElMessage class with the main part set to the previously created instance of TElMultiPartList class;
  3. Setup message parameters (the code snippet below shows how to use address groups - a named collection of mail addresses);
  4. Create several parts for plain and html texts by creating instances of TElPlainTextPart class and populate them with text;
  5. Set TElMessagePart.ContentSubtype property of the HTML part to "html" string;
  6. Add the text parts to the list part created on step 1 using TElMultipartList.AddPart() method.
  7. Assemble the message to a stream


// step 1
TElMultiPartList listPart = new TElMultiPartList();

// step 2
TElMessage message = new TElMessage(listPart, "My Cool E-mail Client");

// step 3
message.From.AddAddress("Secretary", "sender@company.com");
message.To_.AddAddress("Addressee", "address@domain.com");
message.SetSubject("Test Message");

// step 4
TElPlainTextPart plainPart = new TElPlainTextPart(message);
plainPart.SetText(@"Just a test message");

TElPlainTextPart htmlPart = new TElPlainTextPart(message, message.MainPart);
htmlPart.SetText(@"<html><head></head><body><cite>Just a test message</cite></body></html>");
// step 5

// step 6

// step 7
using (FileStream f = new FileStream(@"D:\test.eml", FileMode.Create, FileAccess.Write))

How To articles about MIME

Discuss this help topic in SecureBlackbox Forum