Discuss this help topic in SecureBlackbox Forum

MIME: Create message with attachment from memory

To add the attachment from memory use TElMessage.AttachData() 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 data. 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.AttachData("", "my data", data, 0, data.Length);

// 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