4AspNet POP3 .NET Component

POP3 Class

Class POP3 Provides properties and methods for downloading e-mail messages using Post Office Protocol 3 (POP3) protocol.

For a list of all members of this type, see POP3 Members.

System.Object
   ForAspNet.POP3.POP3

[Visual Basic]
Public Class POP3
[C#]
public class POP3

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

The POP3 is a central class of the product. It is provides methods for for downloading e-mail messages using Post Office Protocol 3 (POP3) protocol.

Note   Before using of POP3 object make sure what LicenseKey property of License class is set to correct license key string; otherwise the exception of type License.LicenseException will be thrown during initializing of a new instance of POP3 object.

Example

This sample shows how to use the ForAspNet.POP3

ForAspNet.POP3.License.LicenseKey = "<put license string here>";
POP3 objPOP3 = new POP3("mail.server.com", "username", "password");
if (objPOP3.IsAPOPSupported)
{
    if (!objPOP3.SecureLogin()) 
    {
        Console.WriteLine("Can't login: " + objPOP3.LastError);
        Console.ReadLine();
        return;
    }
}
else
{
    if(!objPOP3.Login())
    {
        Console.WriteLine("Can't login: " + objPOP3.LastError);
        Console.ReadLine();
        return;
    }
}
objPOP3.QueryServer();
Console.WriteLine("Emails count: " + objPOP3.TotalMailCount);
for (int i = 1; i <= objPOP3.TotalMailCount; i++)
{
    EmailMessage objEmail = objPOP3.GetMessage(i, false); // use true to get headers only
    Console.WriteLine("NEW MESSAGE:------------------");
    Console.WriteLine("FROM: " + objEmail.From);
    Console.WriteLine("SUBJECT: " + objEmail.Subject);
    Console.WriteLine("DATE: " + objEmail.Date);
    Console.WriteLine("CONTENT-TYPE: " + objEmail.ContentType);
    Console.WriteLine("CHARSET: " + objEmail.Charset);
    Console.WriteLine("MESSAGE-ID: " + objEmail.GetCustomHeader("Message-ID"));
    Console.WriteLine("MESSAGE SIZE: " + objEmail.Size);
    if (objEmail.IsAnyAttachments)
    {
        for(int a = 0; a < objEmail.Attachments.Count; a++)
            processAttachment((Attachment)objEmail.Attachments[a], 1);
    }
    Console.WriteLine("BODY: " + objEmail.Body);
    Console.WriteLine("----------END");
    Console.WriteLine("Press Enter to exit...");
    Console.ReadLine();
    StreamWriter sw = new StreamWriter(@"c:\\pop3\m_" + i.ToString() + ".eml");
    sw.Write(objEmail.ToString());
    sw.Close();
    //objPOP3.DeleteMessage(i);
}
objPOP3.Close();
Console.WriteLine("Connection closed. Press Enter to exit...");
Console.ReadLine();
static void processAttachment(Attachment att, int nesting)
{
    for(int i = 0; i < nesting * 2; i++) Console.Write("-");
    Console.WriteLine("ATT: ");
    Console.WriteLine("ContentTransferEncoding: " + att.ContentTransferEncoding);
    Console.WriteLine("ContentType: " + att.ContentType);
    Console.WriteLine("EstimatedSize: " + att.EstimatedSize);
    Console.WriteLine("FileName: " + att.FileName);
    processBody("HtmlBody", att.HtmlBody);
    processBody("TextBody", att.TextBody);
    Console.WriteLine("IsAnyAttachments: " + att.IsAnyAttachments);
    Console.WriteLine("IsFileAttachment: " + att.IsFileAttachment);
    if (att.IsAnyAttachments)
        for(int a = 0; a < att.Attachments.Count; a++)
            processAttachment((Attachment)att.Attachments[a], nesting * 2);
    for(int i = 0; i < nesting * 2; i++) Console.Write("-");
    Console.ReadLine();
}
static void processBody(string bodytype, string body)
{
    if (body == null) 
    {
        Console.WriteLine(bodytype + ": null");
        return;
    }
    if (body.Length > 1000) 
        Console.WriteLine(bodytype + ": " + body.Substring(0, 1000) + "...");
    else
        Console.WriteLine(bodytype + ": " + body);
}

Requirements

Namespace: ForAspNet.POP3

Assembly: 4AspNet.POP3 (in 4AspNet.POP3.dll)

See Also

POP3 Members | ForAspNet.POP3 Namespace