views:

56

answers:

1

Hy,

I am retrieving mails from a gmail account programaticaly using this libraries http://mailsystem.codeplex.com/ .

Everything it's OK (I get the messages count and a list of all messages) when I run my application for the first time after I set the 'Enable POP for all mail' to OK in the 'Forwarding and POP/IMAP' tab in Settings menu. But when I run it again no messages are being retrieved. And if I go again and set the enable POP for all mail, the application works again.

I think I have to set 'enable POP for all mail' programaticaly before I run the retrieving messages code.

Does anyone have any idea how can I do this programaticaly in C# and asp.net?

The code I'm using:

Pop3Client pop = new Pop3Client();
        try
        {
            Label7.Text = string.Format("Connection to the pop 3 server : {0}", "pop.gmail.com ");
            pop.ConnectSsl("pop.gmail.com", 995, TextBox4.Text, TextBox5.Text);

            Label7.Text += string.Format("Message Count: {0}", pop.MessageCount.ToString());
            MessageCollection mc = new MessageCollection();
            for (int n = 1; n < pop.MessageCount + 1; n++)
            {
                Message newMessage = pop.RetrieveMessageObject(n);
                mc.Add(newMessage);

                 Label7.Text += string.Format("Message ({0}) : {1} ", n.ToString(), newMessage.Subject);
            }
        }

        catch (Pop3Exception pexp)
        {
            Label7.Text = string.Format("Pop3 Error: {0} ", pexp.Message);
        }

        catch (Exception ex)
        {
            Label7.Text = string.Format("Failed: {0} ", ex.Message);
        }

        finally
        {
            if (pop.IsConnected)
            {
                pop.Disconnect();
            }
        }

And I'm using the ActiveUp.Net.Mail library from the source I've mentioned before.

+1  A: 

Are you trying to get the IMAP4 behavior with POP3?

With POP3, the email is usually deleted from the server once retrieved. Then only new messages will become available in your application the next time you connext. And so on.

With IMAP4, the messages remains on the server. It's a different approach. You have to maintain a state locally that will synchronize with your IMAP4 server.

Pierre 303
That is what I don't understand... why I cannot retrieve the same mails with pop3 when I run the application the second time, the third time and so on. My gmail account is configured with pop.gmail.com at incoming mail server.
Jeff Norman
I think it's some logic Gmail provide to prevent client from downloading 2 times the same message between 2 sessions. If you really want to download multiple times the same message, opt for IMAP4
Pierre 303
hmmm... I've tried with IMAP4 but isn't working (and that is logic because my incoming mail server is pop.gmail.com, POP3). Is there any other way to retrieve the same messages in 2 sessions?
Jeff Norman
Yes don't use gmail, use another POP3 server instead
Pierre 303