Discuss this help topic in SecureBlackbox Forum

MIME: Create message with attachment from file

The simplest way to add attachments is to use TElMessage.AttachFile() method. It creates a message with the following structure:

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

The following code snippet creates a plain text message with an attached file. To specify another content type for the attached data, pass the desired type as the first parameter.


// step 1: create objects
TElPlainTextPart textPart = new TElPlainTextPart();
TElMessage message = new TElMessage(textPart, "My Cool E-mail Client");

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

// step 3: put message text
textPart.SetText(@"Just a test message");

// step 4: attach a file
message.AttachFile("", @"D:\cert.cer");

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

How To articles about MIME

Discuss this help topic in SecureBlackbox Forum