Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.8.0+

Demonstrates how to call AddPemSource for an Email Object

Demonstrates how to call AddPemSource for an Email Object, with PEM text that was read into a string.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFac
    String sPemText
    Variant vPem
    Handle hoPem
    Handle hoEmail
    String sTemp1

    Move False To iSuccess

    //  The PEM text (a certificate and its private key) is read into a string.
    Get Create (RefClass(cComCkFileAccess)) To hoFac
    If (Not(IsComObjectCreated(hoFac))) Begin
        Send CreateComObject of hoFac
    End
    Get ComReadEntireTextFile Of hoFac "qa_data/pem/some.pem" "utf-8" To sPemText

    //  Load the PEM text into a Pem object.  The 2nd argument of LoadPem is the password of the
    //  private key.  (Pass an empty string if the private key is not encrypted.)
    Get Create (RefClass(cComChilkatPem)) To hoPem
    If (Not(IsComObjectCreated(hoPem))) Begin
        Send CreateComObject of hoPem
    End
    Get ComLoadPem Of hoPem sPemText "PEM_PASSWORD" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoPem To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get pvComObject of hoPem to vPem
    Get ComAddPemSource Of hoEmail vPem To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Success."


End_Procedure