Sample code for 30+ languages & platforms
DataFlex

B-Encode a String for MIME Headers

See more Email Object Examples

Demonstrates the Chilkat Email.BEncodeString method, which converts the Unicode string in the first argument to the charset named in the second argument, B-encodes the resulting multibyte data, and returns the encoded string. This is the representation used for non-ASCII text in MIME header fields.

Background: MIME headers were defined to carry only plain ASCII, so non-ASCII text (accents, non-Latin scripts) must be wrapped in an "encoded-word" per RFC 2047. The B encoding is Base64-based: the text becomes something like =?utf-8?B?...?=, which mail software recognizes and decodes back to the original characters. There is also a Q (quoted-printable-style) encoding for the same purpose; B-encoding is preferred when most characters are non-ASCII.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    String sEncoded

    //  Demonstrates the BEncodeString method, which converts a Unicode string to a specified
    //  charset, B-encodes (RFC 2047) the resulting bytes, and returns the encoded string.
    //  This is the form used for non-ASCII text in MIME header fields.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    //  B-encode a Unicode string using the utf-8 charset.
    Get ComBEncodeString Of hoEmail "Cafe Meeting Notes" "utf-8" To sEncoded

    Showln "B-encoded: " sEncoded


End_Procedure