AutoIt
AutoIt
IMAP Download and Verify Signed (S/MIME) Email
See more IMAP Examples
Demonstrates how to download and verify digitally signed S/MIME email.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oImap = ObjCreate("Chilkat.Imap")
; Connect to an IMAP server.
; Use TLS
$oImap.Ssl = True
$oImap.Port = 993
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Login("myLogin","myPassword")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Select an IMAP mailbox
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; We can choose to fetch UIDs or sequence numbers.
Local $bFetchUids = True
; Get the message IDs of all the emails in the mailbox
$oMessageSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("ALL",$bFetchUids,$oMessageSet)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$oEmail = ObjCreate("Chilkat.Email")
$oCert = ObjCreate("Chilkat.Cert")
Local $i = 0
While $i < $oMessageSet.Count
Local $sUid = $oMessageSet.GetId($i)
ConsoleWrite("uid: " & $sUid & @CRLF)
$bSuccess = $oImap.FetchEmail(False,$sUid,True,$oEmail)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; 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 ($oEmail.ReceivedSigned = True) Then
ConsoleWrite("This email was signed." & @CRLF)
; Check to see if the signatures were verified.
If ($oEmail.SignaturesValid = True) Then
ConsoleWrite("Digital signature(s) verified." & @CRLF)
ConsoleWrite("Signer: " & $oEmail.SignedBy & @CRLF)
; Get the certificate used for signing.
$bSuccess = $oEmail.LastSignerCert(0,$oCert)
If ($bSuccess = False) Then
ConsoleWrite("Failed to get signing certificate object." & @CRLF)
Else
ConsoleWrite("Signing cert: " & $oCert.SubjectCN & @CRLF)
EndIf
Else
ConsoleWrite("Digital signature verification failed." & @CRLF)
EndIf
EndIf
$i = $i + 1
Wend
; Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()