Sample code for 30+ languages & platforms
Lianja

POP3 Verify Signed (S/MIME) Email

Demonstrates how to download and verify digitally signed S/MIME email.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loMailman = createobject("CkMailMan")

// Set the POP3 server's hostname
loMailman.MailHost = "pop.example.com"

// Set the POP3 login/password.
loMailman.PopUsername = "myLogin"
loMailman.PopPassword = "myPassword"

loStUidls = createobject("CkStringTable")
llSuccess = loMailman.FetchUidls(loStUidls)
if (llSuccess = .F.) then
    ? loMailman.LastErrorText
    release loMailman
    release loStUidls
    return
endif

loEmail = createobject("CkEmail")
loCert = createobject("CkCert")

lnCount = loStUidls.Count
i = 0
do while i < lnCount
    // Download the full email.
    llSuccess = loMailman.FetchByUidl(loStUidls.StringAt(i),.F.,0,loEmail)
    if (llSuccess = .F.) then
        ? loMailman.LastErrorText
        release loMailman
        release loStUidls
        release loEmail
        release loCert
        return
    endif

    ? str(i)
    ? "From: " + loEmail.From
    ? "Subject: " + loEmail.Subject

    // The security layers of signed and/or encrypted emails
    // are automatically "unwrapped" when loaded into
    // a Chilkat email object.
    // An application only needs to check to see if an email
    // was received signed or encrypted, and then examine
    // the success/failure.  For example:
    if (loEmail.ReceivedSigned = .T.) then

        ? "This email was signed."

        // Check to see if the signatures were verified.
        if (loEmail.SignaturesValid = .T.) then
            ? "Digital signature(s) verified."
            ? "Signer: " + loEmail.SignedBy

            llSuccess = loEmail.LastSignerCert(0,loCert)
            if (llSuccess = .F.) then
                ? loEmail.LastErrorText
                release loMailman
                release loStUidls
                release loEmail
                release loCert
                return
            endif

            ? "Signing cert: " + loCert.SubjectCN
        endif

    else
        ? "Digital signature verification failed."
    endif

    i = i + 1
enddo

loMailman.Pop3EndSession()


release loMailman
release loStUidls
release loEmail
release loCert