C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Read S/MIME Encrypted Email

Read S/MIME encrypted email.

Download Chilkat .NET for 4.0 Framework

Download Chilkat .NET for 64-bit 4.0 Framework (x64)

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)

Download Chilkat .NET for 1.0 / 1.1 Framework

Chilkat.Imap imap = new Chilkat.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) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Login
success = imap.Login("myLogin","myPassword");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    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.AutoUnwrapSecurity = true;

//  The NumMessages property contains the number of messages in the selected mailbox.
int numToFetch;
numToFetch = imap.NumMessages;
//  Download all the email in the Inbox.
Chilkat.EmailBundle bundle = null;
bundle = imap.FetchSequence(1,numToFetch);
if (bundle == null ) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Loop over the bundle,
int i;
for (i = 0; i <= bundle.MessageCount - 1; i++) {
    Chilkat.Email email = null;
    email = bundle.GetEmail(i);

    textBox1.Text += email.From + "\r\n";
    textBox1.Text += email.Subject + "\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.ReceivedEncrypted == true) {

        textBox1.Text += "This email was encrypted when received." + "\r\n";
        if (email.Decrypted == true) {
            textBox1.Text += "This email was successfully decrypted.  It was encrypted by:" + "\r\n";
            textBox1.Text += email.EncryptedBy + "\r\n";
        }
        else {
            textBox1.Text += "This email was not decrypted." + "\r\n";
        }

    }

    if (email.ReceivedSigned == true) {

        textBox1.Text += "This email was signed when received." + "\r\n";
        if (email.SignaturesValid == true) {
            textBox1.Text += "The signature was verified.  It was signed by:" + "\r\n";
            textBox1.Text += email.SignedBy + "\r\n";
        }
        else {
            textBox1.Text += "The signature verification failed." + "\r\n";
        }

    }

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

    textBox1.Text += "--" + "\r\n";

}

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


 

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

Email Component · XML Parser