0 votes

how to fetch all mail from beginning to end by pop3 mail either it may be read or unread


1 Answer

0 votes

Code is quite simple:

using(Pop3 pop3 = new Pop3())
    pop3.Connect("pop3.server.com");  // or ConnectSSL for SSL      
    pop3.UseBestLogin("user", "password");

    List<string> uids = pop3.GetAll();
    foreach (string uid in uids)
        var eml = pop3.GetMessageByUID(uid);

        IMail email = new MailBuilder().CreateFromEml(eml);

        string subject = email.Subject;

Now, depending on your server and your server configuration, not all emails might be returned.

For example in Gmail, you can enable POP3 for all messages -or- only for mail that arrives from now on.

Take a look at Gmail's POP3 behavior here:

Some servers may limit the amount of messages they return.
Consider using IMAP protocol, IMAP is usually not affected by such limits.

by (297k points)