MFC Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

MFC Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
MIME
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip


 

 

 

 

 

 

 

 

Read S/MIME Encrypted Email

Read S/MIME encrypted email.

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

// Needs #include <CkImap.h>
// Needs #include <CkEmailBundle.h>
// Needs #include <CkEmail.h>

    CkString strOut;

    CkImap imap;

    bool success;

    //  Anything unlocks the component and begins a fully-functional 30-day trial.
    success = imap.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Connect to an IMAP server.
    success = imap.Connect("mail.chilkatsoft.com");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Login
    success = imap.Login("myLogin","myPassword");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Select an IMAP mailbox
    success = imap.SelectMailbox("Inbox");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  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.
    long numToFetch;
    numToFetch = imap.get_NumMessages();
    //  Download all the email in the Inbox.
    CkEmailBundle *bundle = 0;
    bundle = imap.FetchSequence(1,numToFetch);
    if (bundle == 0 ) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Loop over the bundle,
    long i;
    for (i = 0; i <= bundle->get_MessageCount() - 1; i++) {
        CkEmail *email = 0;
        email = bundle->GetEmail(i);

        strOut.append(email->ck_from());
        strOut.append("\r\n");
        strOut.append(email->subject());
        strOut.append("\r\n");

        //  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) {

            strOut.append("This email was encrypted when received.");
            strOut.append("\r\n");
            if (email->get_Decrypted() == true) {
                strOut.append("This email was successfully decrypted.  It was encrypted by:");
                strOut.append("\r\n");
                strOut.append(email->encryptedBy());
                strOut.append("\r\n");
            }
            else {
                strOut.append("This email was not decrypted.");
                strOut.append("\r\n");
            }

        }

        if (email->get_ReceivedSigned() == true) {

            strOut.append("This email was signed when received.");
            strOut.append("\r\n");
            if (email->get_SignaturesValid() == true) {
                strOut.append("The signature was verified.  It was signed by:");
                strOut.append("\r\n");
                strOut.append(email->signedBy());
                strOut.append("\r\n");
            }
            else {
                strOut.append("The signature verification failed.");
                strOut.append("\r\n");
            }

        }

        //  The email's body, HTML body, attachments, etc.
        //  are decrypted and available just like any non-encrypted email.

        strOut.append("--");
        strOut.append("\r\n");
        delete email;
    }

    //  Disconnect from the IMAP server.
    imap.Disconnect();

    delete bundle;

    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

Need a specific example? Send a request to support@chilkatsoft.com

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