Sample code for 30+ languages & platforms
JavaScript Requires Chilkat v11.0.0+

Find the text in an archived T-Mobile gateway email

See more Email Object Examples

Some archived gateway messages carry the SMS text as a related MIME item. Check for an ordinary text body first, then inspect related items by media type. The related-text branch assumes UTF-8, as in the sample format. It reads a saved email and needs no carrier service.

Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

var email = new CkEmail();
success = email.LoadEml("gateway.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

if (email.HasPlainTextBody() == true) {
    console.log(email.GetPlainTextBody());
    return;
}

var mediaType = new CkStringBuilder();
var i = 0;
while ((i < email.NumRelatedItems)) {
    mediaType.SetString(email.GetRelatedContentType(i));
    if (mediaType.ContentsEqual("text/plain",false) == true) {
        console.log(email.GetRelatedString(i,"utf-8"));
        return;
    }

    i = i+1;
}

console.log("No text body or related text/plain part.");