Sample code for 30+ languages & platforms
PureBasic

Check Whether an Email Has a Plain-Text Body

See more Email Object Examples

Demonstrates the Chilkat Email.HasPlainTextBody method, which returns true only when a text/plain body is present in the current email object. This example sets a plain-text body and confirms its presence.

Background: The plain-text body is the fallback representation used when HTML is unavailable or unwanted — and the form usually preferred for search, indexing, and accessibility. HasPlainTextBody is the counterpart to HasHtmlBody; testing both lets a program handle every combination (text-only, HTML-only, both, or neither) gracefully.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    ;  Demonstrates the HasPlainTextBody method, which returns true only when a text/plain body
    ;  is present in the current email object.

    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkEmail::setCkSubject(email, "HasPlainTextBody example")

    CkEmail::ckSetTextBody(email,"Hello, this is the plain-text body.","text/plain")

    If CkEmail::ckHasPlainTextBody(email) = 1
        Debug "The email has a plain-text body."
    Else
        Debug "The email does not have a plain-text body."
    EndIf



    CkEmail::ckDispose(email)


    ProcedureReturn
EndProcedure