We are using OpenPop.NET dll for accessing emails via gmail. We are able to get emails but unfortunately we are not able to delete emails via C#. Whenever we are trying to delete the emails it is throwing an error as mentioned below:
You cannot delete the message without authenticating yourself towards the server first.
We have already authenticated ourselves towards the server at the first line then we are processing the message and deleting. At the end we are calling Disconnect in order to delete it from POP server.
Please find below our code snippet:
string Mailaddress = Convert.ToString(ConfigurationManager.AppSettings["EmailAddress"]);
string Password = Convert.ToString(ConfigurationManager.AppSettings["Password"]);
pop3Client = new Pop3Client();
pop3Client.Connect("pop.gmail.com", 995, true);
pop3Client.Authenticate(Mailaddress, Password);
messages.Clear();
int count = pop3Client.GetMessageCount();
for (i = count; i >= 1; i -= 1)
{
Message message = pop3Client.GetMessage(i);
ParseMessageBody(message);
pop3Client.DeleteMessage(i);
}
Please let us know what we are we missing.