Sample code for 30+ languages & platforms
DataFlex

Get the Full MIME of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.GetMime method, which returns the email as RFC822/MIME text containing the headers, body representations, related items, and attachments. The result is suitable for saving as a .eml file. This example builds a message and prints its MIME.

Background: MIME is the on-the-wire text format of an email — the exact bytes a mail server sends and receives. GetMime serializes the in-memory Email object into that format, assembling headers, encoding attachments as Base64, and adding the multipart boundaries that separate the parts. It is the natural way to persist a message (as .eml), inspect exactly what will be transmitted, or hand the message to another system.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    String sTemp1

    //  Demonstrates the GetMime method, which returns the email as RFC822/MIME text containing
    //  the headers, body representations, related items, and attachments.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "GetMime example"
    Set ComFrom Of hoEmail To "alice@example.com"
    Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
    Set ComBody Of hoEmail To "Hello, this is the message body."

    //  Get the complete RFC822/MIME text (suitable for saving as a .eml file).
    Get ComGetMime Of hoEmail To sTemp1
    Showln sTemp1


End_Procedure