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

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Assumes Chilkat is unlocked. See Global Unlock Sample.

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

    CkEmail::setCkFrom(email, "Sam Lee <sam@example.com>")
    success = CkEmail::ckAddTo(email,"Alex Rivera","alex@example.net")
    If success <> 1
        Debug CkEmail::ckLastErrorText(email)
        CkEmail::ckDispose(email)
        ProcedureReturn
    EndIf

    CkEmail::setCkSubject(email, "Hello")
    CkEmail::setCkBody(email, "This is a plain-text message.")
    success = CkEmail::ckSaveEml(email,"message.eml")
    If success <> 1
        Debug CkEmail::ckLastErrorText(email)
        CkEmail::ckDispose(email)
        ProcedureReturn
    EndIf

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

    success = CkEmail::ckLoadEml(received,"message.eml")
    If success <> 1
        Debug CkEmail::ckLastErrorText(received)
        CkEmail::ckDispose(email)
        CkEmail::ckDispose(received)
        ProcedureReturn
    EndIf

    Debug CkEmail::ckFrom(received)
    Debug CkEmail::ckSubject(received)
    Debug CkEmail::ckGetPlainTextBody(received)


    CkEmail::ckDispose(email)
    CkEmail::ckDispose(received)


    ProcedureReturn
EndProcedure