Delete Email Error

Oct 5, 2010 at 7:13 PM

Hi Guys, hello Again,
scuse me if I'm boring but I had some problems with the c# Mail
library  ...and I am not able to understand all the reason.  At this moment I don't know why the emails are not deleted from my account ... I don't catch error, my routine looks good but when I see my email account all posts are still there waiting for me :(

I put the delete function to a method of my routine like this

public void myroutine(string Object, string EmailAdd, long IDemail)
{
      //some fuctions
      if (somevar == 0)
      {
         using (Pop3Client cl = new Pop3Client())
         { cl.UserName = "mymail@mydomian.com"; cl.Password = "mypass"; cl.ServerName = "mail.myserver.com"; cl.AuthenticateMode = Pop3AuthenticateMode.Pop; cl.Authenticate(); cl.DeleteEMail(IDemail); cl.ExecuteQuit; } } }

I call my function in this way

        Pop3Client pop = new Pop3Client("mymail@mydomain.com", "mypass", "mail.myserver.com");
        pop.Port = 110;
        pop.AuthenticateMode = Pop3AuthenticateMode.Pop;

        pop.Authenticate();

        if (pop.State == Pop3ConnectionState.Authenticated)
        {
            long totalMsgs = pop.GetTotalMessageCount();


            for (long i = 2; i <= totalMsgs; i++)
            {
                Pop3Message msg = pop.GetMessage(i); 
                myroutine(Convert.ToString(msg.Subject), Convert.ToString(msg.BodyText), (long)msg.Index); }
What the hell I'm wrong?!
Thanks you again!!

Coordinator
Oct 6, 2010 at 2:22 PM

Pop3 server can deal one connection per single user.
So,you must call once Authenticate method.

Apr 26, 2011 at 12:05 PM
Edited Apr 26, 2011 at 12:07 PM

If I have a lot of emails (100-300) and I need to delete them, I spend a lot of time for Authenticate() process. Does anybody know how to delete "pack" emails (I have exchange)?

Coordinator
May 1, 2011 at 12:54 PM

Again,you must call once Authenticate method.
You call Authenticate method first layer and inside myroutine method.
And call once ExecuteQuit method when finishing your delete process.

Additionally mentioning, the Authenticate method negotiate to server and may cause some delay.
So,too much call Authenticate method cause performance issue.

You can delete all mail at a time, I will show you the cocept code.
--------------------------------------------------------------------------
Pop3Client pop = new Pop3Client("mymail@mydomain.com", "mypass", "mail.myserver.com");
pop.Port = 110;
pop.AuthenticateMode = Pop3AuthenticateMode.Pop;
pop.Authenticate();
long[] DeleteIndexList = new.....//It depend on your needs
//It is better to target for exact mail that you want to delete.
foreach (long index in DeleteIndexList)
{
     cl.DeleteEMail(i);
}
pop.ExecuteQuit();
--------------------------------------------------------------------------


Hope your help.