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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Email
oleobject loo_MediaType
long i

li_Success = 0

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

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Email.LoadEml("gateway.eml")
if li_Success <> 1 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

if loo_Email.HasPlainTextBody() = 1 then
    Write-Debug loo_Email.GetPlainTextBody()
    destroy loo_Email
    return
end if

loo_MediaType = create oleobject
li_rc = loo_MediaType.ConnectToNewObject("Chilkat.StringBuilder")

i = 0
do while (i < loo_Email.NumRelatedItems)
    loo_MediaType.SetString(loo_Email.GetRelatedContentType(i))
    if loo_MediaType.ContentsEqual("text/plain",0) = 1 then
        Write-Debug loo_Email.GetRelatedString(i,"utf-8")
        destroy loo_Email
        destroy loo_MediaType
        return
    end if

    i = i + 1
loop
Write-Debug "No text body or related text/plain part."


destroy loo_Email
destroy loo_MediaType