Discuss this help topic in SecureBlackbox Forum

MIME: Create message with alternative parts and attachment

To add the attachment from memory use TElMessage.AttachData() method. If a message with alternative texts and attached data needs to be created, the following parts structure has to be used:

  • multipart/mixed
    • multipart/alternative
      • text/html
      • text/plain
    • application/octet-stream or the specified one
    • and so on for each added attachment


// create objects
TElMessage message = new TElMessage(new TElMultiPartList(), "My Cool E-mail Client");

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

// create a list for the text parts and add it to the main message part
TElMultiPartList listPart = new TElMultiPartList(message);

// create a plain text part and add it to the list
TElPlainTextPart plainPart = new TElPlainTextPart(message);
plainPart.SetText(@"Just a test message");

// create a HTML text part and add it to the list
TElPlainTextPart htmlPart = new TElPlainTextPart(message, message.MainPart);
htmlPart.SetText(@"<html><head></head><body><cite>Just a test message</cite></body></html>");

// attach necessary data
message.AttachData("", "my data", data, 0, data.Length);

// assemble and save the message
using (FileStream f = new FileStream(@"D:\test.eml", FileMode.Create, FileAccess.Write, FileShare.Read))

How To articles about MIME

Discuss this help topic in SecureBlackbox Forum