Sample code for 30+ languages & platforms
Visual FoxPro

POP3 Verify Signed (S/MIME) Email

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

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMailman
LOCAL loStUidls
LOCAL loEmail
LOCAL loCert
LOCAL lnCount
LOCAL i

lnSuccess = 0

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

loMailman = CreateObject('Chilkat.MailMan')

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

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

loStUidls = CreateObject('Chilkat.StringTable')
lnSuccess = loMailman.FetchUidls(loStUidls)
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    RELEASE loStUidls
    CANCEL
ENDIF

loEmail = CreateObject('Chilkat.Email')
loCert = CreateObject('Chilkat.Cert')

lnCount = loStUidls.Count
i = 0
DO WHILE i < lnCount
    * Download the full email.
    lnSuccess = loMailman.FetchByUidl(loStUidls.StringAt(i),0,0,loEmail)
    IF (lnSuccess = 0) THEN
        ? loMailman.LastErrorText
        RELEASE loMailman
        RELEASE loStUidls
        RELEASE loEmail
        RELEASE loCert
        CANCEL
    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 = 1) THEN

        ? "This email was signed."

        * Check to see if the signatures were verified.
        IF (loEmail.SignaturesValid = 1) THEN
            ? "Digital signature(s) verified."
            ? "Signer: " + loEmail.SignedBy

            lnSuccess = loEmail.LastSignerCert(0,loCert)
            IF (lnSuccess = 0) THEN
                ? loEmail.LastErrorText
                RELEASE loMailman
                RELEASE loStUidls
                RELEASE loEmail
                RELEASE loCert
                CANCEL
            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