Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Tcl Examples
Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Apple Keychain
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Tcl) POP3 Verify Signed (S/MIME) Email

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

Note: This example requires Chilkat v11.0.0 or greater.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

set success 0

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

set mailman [new_CkMailMan]

# Set the POP3 server's hostname
CkMailMan_put_MailHost $mailman "pop.example.com"

# Set the POP3 login/password.
CkMailMan_put_PopUsername $mailman "myLogin"
CkMailMan_put_PopPassword $mailman "myPassword"

set stUidls [new_CkStringTable]

set success [CkMailMan_FetchUidls $mailman $stUidls]
if {$success == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    delete_CkStringTable $stUidls
    exit
}

set email [new_CkEmail]

set cert [new_CkCert]

set count [CkStringTable_get_Count $stUidls]
set i 0
while {$i < $count} {
    # Download the full email.
    set success [CkMailMan_FetchByUidl $mailman [CkStringTable_stringAt $stUidls $i] 0 0 $email]
    if {$success == 0} then {
        puts [CkMailMan_lastErrorText $mailman]
        delete_CkMailMan $mailman
        delete_CkStringTable $stUidls
        delete_CkEmail $email
        delete_CkCert $cert
        exit
    }

    puts "$i"
    puts "From: [CkEmail_from $email]"
    puts "Subject: [CkEmail_subject $email]"

    # 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 {[CkEmail_get_ReceivedSigned $email] == 1} then {

        puts "This email was signed."

        # Check to see if the signatures were verified.
        if {[CkEmail_get_SignaturesValid $email] == 1} then {
            puts "Digital signature(s) verified."
            puts "Signer: [CkEmail_signedBy $email]"

            set success [CkEmail_LastSignerCert $email 0 $cert]
            if {$success == 0} then {
                puts [CkEmail_lastErrorText $email]
                delete_CkMailMan $mailman
                delete_CkStringTable $stUidls
                delete_CkEmail $email
                delete_CkCert $cert
                exit
            }

            puts "Signing cert: [CkCert_subjectCN $cert]"
        }

    }     else {
        puts "Digital signature verification failed."
    }

    set i [expr $i + 1]
}

CkMailMan_Pop3EndSession $mailman

delete_CkMailMan $mailman
delete_CkStringTable $stUidls
delete_CkEmail $email
delete_CkCert $cert

 

© 2000-2025 Chilkat Software, Inc. All Rights Reserved.