Sample code for 30+ languages & platforms
Node.js

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 Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

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

    var email = new chilkat.Email();

    //  B-encode a Unicode string using the utf-8 charset.
    var encoded = email.BEncodeString("Cafe Meeting Notes","utf-8");

    console.log("B-encoded: " + encoded);

}

chilkatExample();