Delete email

Jan 8, 2011 at 9:14 AM
Edited Jan 8, 2011 at 9:50 AM


I am trying to delete an email from my Gmail account with Higuchi.Mail.dll (2010.10.13 ver). After running the following code, the mail is still there  when I check it from the Gmail website. I also noticed that the return value of the call to cl.GetTotalMessageCount() was reduced after the test.


 ***Test code***

    using (Pop3Client cl = new Pop3Client(UserName, Password, Server))
        cl.Port = Port;
        cl.Ssl = true;


Any suggestions?




Jan 9, 2011 at 5:40 AM

Thank you for your post.
Althouth I don't know inside of GMail,probably GMail deal with their mail as their own logic.
See these

I can't find a way to solve this problem.
If you can find a way, please post the way and share the information that help all people using C#Mail.


Jan 9, 2011 at 9:07 AM

Thank you for your reply.

As a workaround, I can delete email from the GMail server in a non-standard way: If selecting "When messages are accessed with POP delete GMail’s copy" (a GMail account setting), then email downloaded via POP3 will be automatically deleted from the server.

However, I am going to deal with a standard POP3 server later. I have another question:

I tried to call GetTotalMessageCount() after calling ExecuteQuit(), it failed. Is there a way to resolve it without re-authenticating the POP3 client? 





Jan 11, 2011 at 11:11 AM

In POP3 spec,quit command is a sign that operation is completed.
And server would disconnect the connection to the client.
I assume that 99% pop3 server would be implemented as disconnect the connection when receive quit command.
So,you must recreate the connection by authenticating to pop3 server.

I suggest that you call GetTotalMessageCount() before operation.
And you can manage the count of delete mail in your app's memory.
Simply calling DeleteEMail(),you increment 1 to your local variable.
After ExecuteQuit(),you can get the number of your mailbox from TotalMessageCountBeforeOperation - DeleteMailCount = TotalMessageCountAfterOperation.

Is it your help??

Jan 11, 2011 at 1:09 PM

Got it. Thank you very much!

Apr 25, 2011 at 11:38 PM

I have problems deleting mails too. When I try delete all mails, it only del the first one and disconnect from server.

My code:

string usuario = config.obtenValor("pop3cliente", "usuario");
string clave = config.obtenValor("pop3cliente", "clave");
string servidor = config.obtenValor("pop3cliente", "servidor");
string puerto = config.obtenValor("pop3cliente", "puerto");
Higuchi.Net.Pop3.Pop3Client ClientePOP3 = new Higuchi.Net.Pop3.Pop3Client(usuario, clave, servidor);
ClientePOP3.Port = Int32.Parse(puerto);
bool aut = ClientePOP3.Authenticate();
int numMensajes = Convert.ToInt32(ClientePOP3.GetTotalMessageCount());
if (numMensajes > 0)
    for (int i = 1; i <= numMensajes; i++)
        Higuchi.Net.Pop3.Pop3Message mensaje = ClientePOP3.GetMessage((long)i);
        foreach (Higuchi.Net.Pop3.Pop3Content contenido in mensaje.Contents)
            if (contenido.ContentDisposition.FileName.ToString().Length > 0)
                string ruta = @"C\:" + contenido.ContentDisposition.FileName;


Apr 26, 2011 at 11:10 AM

You need to reconect to the server and delete all your's emails in loop (for delete one email you will make reconection )

May 1, 2011 at 11:56 AM


And quote from above thread topic.
Pop3Client pop = new Pop3Client("", "mypass", "");
pop.Port = 110;
pop.AuthenticateMode = Pop3AuthenticateMode.Pop;
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)
//Call once when finishing your delete process.

I hope this solve your problem!

May 1, 2011 at 8:40 PM

Ok, now I can delete the emails.


May 4, 2011 at 9:17 AM

Thank you.  I have used ExecuteDele() with DeleteEMail() and have one (last index) deleted email.