Sample code for 30+ languages & platforms
C# Requires Chilkat v11.0.0+

Preview POP3 messages and download a complete email

See more Email Object Examples

Read a short preview for each of up to five messages into an EmailBundle, print their subjects, and download the complete first entry into a separate Email. Configure a POP3 account that supports UIDL and TOP. All messages stay on the server.

Chilkat C# Downloads

C#
bool success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

Chilkat.MailMan mail = new Chilkat.MailMan();
mail.MailHost = "pop.example.com";
mail.MailPort = 995;
mail.PopSsl = true;
mail.RequireSslCertVerify = true;
mail.PopUsername = "MAIL_USER";
mail.PopPassword = "MAIL_PASSWORD";
Chilkat.EmailBundle previews = new Chilkat.EmailBundle();
//  Keep the messages and request minimal previews. Range indexes are zero-based and inclusive.
success = mail.FetchRange(true,true,0,0,4,previews);
if (success != true) {
    Debug.WriteLine(mail.LastErrorText);
    return;
}

if (previews.MessageCount == 0) {
    Debug.WriteLine("There are no messages to preview.");
    success = mail.Pop3EndSession();
    if (success != true) {
        Debug.WriteLine(mail.LastErrorText);
        return;
    }

    return;
}

Chilkat.Email header = new Chilkat.Email();
int i = 0;
while ((i < previews.MessageCount)) {
    success = previews.EmailAt(i,header);
    if (success != true) {
        Debug.WriteLine(previews.LastErrorText);
        return;
    }

    Debug.WriteLine(header.Uidl + "  " + header.Subject);
    i = i + 1;
}

//  A UI could use its selected row here. FetchFull uses the preview's POP3 identity.
success = previews.EmailAt(0,header);
if (success != true) {
    Debug.WriteLine(previews.LastErrorText);
    return;
}

Chilkat.Email email = new Chilkat.Email();
success = mail.FetchFull(header,email);
if (success != true) {
    Debug.WriteLine(mail.LastErrorText);
    return;
}

success = mail.Pop3EndSession();
if (success != true) {
    Debug.WriteLine(mail.LastErrorText);
    return;
}

Debug.WriteLine("Full message: " + email.Subject + "  Files: " + Convert.ToString(email.NumAttachments));

success = email.SaveEml("pop-received.eml");
if (success != true) {
    Debug.WriteLine(email.LastErrorText);
    return;
}

Debug.WriteLine("Saved pop-received.eml.");