Reputation: 1044
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.
Upvotes: 3
Views: 3409
Reputation:
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.
Upvotes: 2