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

 

 

 

 

 

 

Alternative Methods of Reading Email from a POP3 Mailbox

Download: Chilkat .NET Assemblies

Discusses a few different ways email can be read from a POP3 server using the Chilkat mail component.

// This example discusses a few of the various ways of reading email from a POP3 server
// using the Chilkat Email Component.
        private void reading_email()
        {
            Chilkat.Email email;

            Chilkat.MailMan mailman = new Chilkat.MailMan();
            mailman.UnlockComponent("Anything for 30-day trial");

            // Set our POP3 mail host and login
            mailman.MailHost = "mail.chilkatsoft.com";
            mailman.PopUsername = "****";
            mailman.PopPassword = "****";

            // In no particular order....

            // ------------------------------------
            // 1: TransferMail
            // ------------------------------------
            // Transfer mail downloads all email from the mailbox and removes
            // each email downloaded from the POP3 server.
            // We can set limits on the maximum number of emails to download,
            // or the maximum size so that any emails larger that the max size are skipped
            // (and remain on the server)
            mailman.MaxCount = 20;   // Don't download more than 20 messages. Emails not downloaded will remain on the server.
            mailman.SizeLimit = 512000;  // Don't download emails greater than 512,000 bytes in size.

            Chilkat.EmailBundle bundle = mailman.TransferMail();
            if (bundle == null)
            {
                MessageBox.Show(mailman.LastErrorText);
                return;
            }

            // You may iterate over the bundle to do whatever it is your program needs
            // to do with each email...
            int i;
            int n = bundle.MessageCount;
            for (i = 0; i < n; i++)
            {
                email = bundle.GetEmail(i);
                // ....
            }

            // ------------------------------------
            // 2: CopyMail
            // ------------------------------------
            // This is the same as TransferMail, except the mail is left on the POP3 server.
            bundle = mailman.CopyMail();

            // ------------------------------------
            // 3: GetAllHeaders and then get selected emails
            // on demand via GetFullEmail
            // ------------------------------------
            // Download the email headers and 1 or more lines of the body.
            // A bundle of email objects is returned, but each email in the bundle
            // will lack the full body, and will not have the attachment information
            // available.  Attachment information is only fully available when the full
            // email has been downloaded from a POP3 server.  This is a limitation
            // of the POP3 protocol (not the Chilkat component).  The IMAP protocol is
            // more feature rich in that headers can be downloaded to include information
            // about attachments.
            int numBodyLines = 1;
            bundle = mailman.GetAllHeaders(numBodyLines);

            // Your program can display summary information about each email, such as the
            // From Address, Recipients, Subject, Date Received, etc.  Your program can
            // download the full email for any given header by calling GetFullEmail.
            // This example shows how to download the full email for the 1st header in
            // the bundle.
            email = bundle.GetEmail(0);
            Chilkat.Email fullEmail = mailman.GetFullEmail(email);
            // ....

            // ------------------------------------
            // 4: GetAllHeaders and then get selected emails
            // on demand via FetchMultiple
            // ------------------------------------
            // Another option is to download the full email for a collection of the header-only
            // emails.  For example, this is how we would download the full emails for all headers
            // where the From address is "invoiceRequest@mycompany.com"
            Chilkat.StringArray uidlArray = new Chilkat.StringArray();

            // Download the headers and build a UIDL array for all emails where the FROM address = "invoiceRequest@mycompany.com"
            bundle = mailman.GetAllHeaders(1);
            n = bundle.MessageCount;
            for (i = 0; i < n; i++)
            {
                email = bundle.GetEmail(i);
                if (email.FromAddress.Equals("invoiceRequest@mycompany.com"))
                {
                    uidlArray.Append(email.Uidl);
                }
            }

            Chilkat.EmailBundle bundle2 = mailman.FetchMultiple(uidlArray);
            // ....
            // Now we can delete the emails in bundle2 from the POP3 server.
            bool success = mailman.DeleteBundle(bundle2);
            // An alternative way of doing it is to delete via the UIDLs:
            success = mailman.DeleteMultiple(uidlArray);
            if (!success)
            {
                MessageBox.Show(mailman.LastErrorText);
                return;
            }

            // ------------------------------------
            // 5: GetUidls and then fetch a set of headers
            // at a time.
            // ------------------------------------
            // For very large mailboxes, there may be so many emails that even downloading
            // headers is too time consuming.  In this case, you can get the complete set
            // of UIDLs and then download a chunk of headers at a time.
            //
            uidlArray = mailman.GetUidls();

            // Perhaps we want the 1st 50 emails...
            int maxIdx = 49;
            if (uidlArray.Count < 50)
            {
                maxIdx = uidlArray.Count - 1;
            }

            // Get a chunk of up to 50 UIDLs
            Chilkat.StringArray uidlChunk = new Chilkat.StringArray();
            if (uidlArray.Count > 0)
            {
                for (i = 0; i < maxIdx; i++)
                {
                    uidlChunk.Append(uidlArray.GetString(i));
                }
            }

            // Download up to 50 headers.
            bundle = mailman.FetchMultipleHeaders(uidlChunk, 1);
            // ....


        }


Important: The download for this example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

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

Email Component · XML Parser