Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Read S/MIME Encrypted EmailRead S/MIME encrypted email.
import sys import chilkat imap = chilkat.CkImap() # Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial") if (success != True): print imap.lastErrorText() sys.exit() # Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com") if (success != True): print imap.lastErrorText() sys.exit() # Login success = imap.Login("myLogin","myPassword") if (success != True): print imap.lastErrorText() sys.exit() # Select an IMAP mailbox success = imap.SelectMailbox("Inbox") if (success != True): print imap.lastErrorText() sys.exit() # The AutoUnwrapSecurity method controls whether signed/encrypted emails are automatically # decrypted and/or verified. # When set to True, which is the default, security envelopes are automatically "unwrapped" # when a message is retrieved from the server. Signed emails are automatically verified, and # encrypted emails are automatically decrypted, restoring the email to the original state before # signing and/or encrypting. Information about the signing and encrypting certificates can be # retrieved from the Email object (methods: GetSignedByCert, GetEncryptedByCert; # properties: SignedBy, EncryptedBy, SignaturesValid, Decrypted, ReceivedSigned, # ReceivedEncrypted). # This example will explicity set AutoUnwrapSecurity to True, even though it's # already the default value: imap.put_AutoUnwrapSecurity(True) # The NumMessages property contains the number of messages in the selected mailbox. numToFetch = imap.get_NumMessages() # Download all the email in the Inbox. bundle = imap.FetchSequence(1,numToFetch) if (bundle == None ): print imap.lastErrorText() sys.exit() # Loop over the bundle, for i in range(0,bundle.get_MessageCount()): email = bundle.GetEmail(i) print email.ck_from() print email.subject() # At this point, if the email was signed and/or encrypted, it is already "unwrapped", i.e. # the email is already decrypted and in a state as if it were never signed or encrypted. # You may check to see if the email was received encrypted or signed, and if so, # whether it was successfully unwrapped and who signed or encrypted it: if (email.get_ReceivedEncrypted() == True): print "This email was encrypted when received." if (email.get_Decrypted() == True): print "This email was successfully decrypted. It was encrypted by:" print email.encryptedBy() else: print "This email was not decrypted." if (email.get_ReceivedSigned() == True): print "This email was signed when received." if (email.get_SignaturesValid() == True): print "The signature was verified. It was signed by:" print email.signedBy() else: print "The signature verification failed." # The email's body, HTML body, attachments, etc. # are decrypted and available just like any non-encrypted email. print "--" # Disconnect from the IMAP server. imap.Disconnect() |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.