Sample code for 30+ languages & platforms
CkPython 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.

Chilkat CkPython Downloads

CkPython
import sys
import chilkat

success = False

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

email = chilkat.CkEmail()
success = email.LoadEml("gateway.eml")
if (success != True):
    print(email.lastErrorText())
    sys.exit()

if (email.HasPlainTextBody() == True):
    print(email.getPlainTextBody())
    sys.exit()

mediaType = chilkat.CkStringBuilder()
i = 0
while (i < email.get_NumRelatedItems()) :
    mediaType.SetString(email.getRelatedContentType(i))
    if (mediaType.ContentsEqual("text/plain",False) == True):
        print(email.getRelatedString(i,"utf-8"))
        sys.exit()

    i = i + 1

print("No text body or related text/plain part.")