We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Purge Email Message Permanetly with POP3 Client

HI Aspose,

I would like to discard/ purge the email message from inbox permanently.
Currently , when I delete from inbox it will move it into trash folder. How can I achieve this?

And also I would like to discard the email once it is sent.
Is it possible in Aspose.Email.POP3.POP3 Client???

Regards
Su


Hi Su,

Thank you for writing to us.

I have tried Imap client with my test Gmail account and the emails are deleted permanently from the inbox/sent folder whichever is selected. Following is the sample code used for this test:
ImapClient imapClient = GetImapClient();
imapClient.Connect();
//imapClient.SelectFolder("Inbox");
imapClient.SelectFolder("[Gmail]/Sent Mail");
imapClient.DeleteMessage(1);

Could you please confirm to us which Mail server are you using? Also please share the code which is being used for deleting the messages.

I would also like to share with you that POP3 is a mail retrieving protocol and can not send emails. Mails can be sent using SmtpClient and ImapClient for permanently deleting email from sent folder.

Please feel free to write us back if you have any other query in this regard.


Hi Kashif Iqbal,

Thanks for the reply.
Below is my scenario and protocol I used .

1)Download the attachment from email message (POP3)
2) Process the downloaded file
3) Reply acknowledgement to sender (SMTP)
4) Discard the email (POP3)

//Discard Email
AsposePop3Client.DeleteMessage(MessageSequenceNo);

Above is the code i use to delete the message.
I am using GMail Client. I found out that the discarded/deleted emails are inside the trash box and the reply (sent mail are in sent box) Is there any other way to delete the sent mail from sent folder?

Best Regards
Su

Hi Su,

Thanks for the feedback.

The POP3 clients are used for retrieval of email messages from the inbox only i.e. it’s access is limited to inbox only and can not access Sent or Trash folders. I am afraid I could not find any such method that could delete the messages permanently from the Gmail inbox.

Since you are sending an acknowledge email via SMTP, it must have a known subject. You can use ImapClient to delete the messages from the Sent folder with the help of this subject as shown in the following code sample:

Sample Code:

ImapClient client = new
ImapClient(“[imap.gmail.com](http://imap.gmail.com/)”,
993, “newcustomeronnet”, “password”);

client.EnableSsl = true;

client.SecurityMode = ImapSslSecurityMode.Implicit;

client.Connect(true);

client.Login();

client.SelectFolder("[Gmail]/Sent Mail");

// Set conditions

ImapQueryBuilder builder = new ImapQueryBuilder();

// Find message with desired subject

builder.Subject.Contains("Reply: Acknowledge");

// Build the query

MailQuery query = builder.GetQuery();

// Get list of messages

ImapMessageInfoCollection messageInfoCol = client.ListMessages(query);

foreach (var messageInfo in messageInfoCol)

{

Console.WriteLine("Deleting: " + messageInfo.Subject);

client.DeleteMessage(messageInfo.SequenceNumber);

client.ExpungeMessages();

}

You can use ImapClient to do the same with deleting messages permanently from inbox as well. Please let us know if we can be of any additional help to you in this regard.

Hi Kashif Iqbal,

Thanks for advice and support. However the code doesn’t seems to work for Gmail .
I tried with your sample code . It always return 0 for no of messages in Sent Box. My suspect is wrong folder name. Not too sure though. Any suggestion?

But it is working for Inbox.
Below is my code.

Aspose.Email.Imap.ImapClient IMAPClient = new Aspose.Email.Imap.ImapClient(txtImapHost.Text, txtImapUserID.Text, txtImapPass.Text);
// Set the security mode to implicit
IMAPClient.SecurityMode = Aspose.Email.Imap.ImapSslSecurityMode.Implicit;
// Enable SSL
IMAPClient.EnableSsl = true;
IMAPClient.Port = int.Parse(txtImpaPORT.Text);

IMAPClient.Connect(true);
IMAPClient.Login();

// GET SENT MAILS
IMAPClient.SelectFolder("[Gmail]/Sent Mail");
// // Get list of messages
Aspose.Email.Imap.ImapMessageInfoCollection messageInfoCol = IMAPClient.ListMessages();
Response.Write(“Sent MAIL COUNT–>”+messageInfoCol.Count);
foreach (var messageInfo in messageInfoCol)
{

Response.Write("Deleting: " + messageInfo.Subject);
IMAPClient.DeleteMessage(messageInfo.SequenceNumber);
IMAPClient.ExpungeMessages();

}

// GET INBOX MAILS

IMAPClient.SelectFolder(“Inbox”);
// Get the message info collection
Aspose.Email.Imap.ImapMessageInfoCollection MessagesInfo = IMAPClient.ListMessages();
Response.Write(“Message Count from inbox–>” + MessagesInfo.Count);
foreach (var messageInfo in MessagesInfo)
{

Response.Write("Deleting:from inbox " + messageInfo.Subject);
IMAPClient.DeleteMessage(messageInfo.SequenceNumber);
IMAPClient.ExpungeMessages();

}
IMAPClient.Disconnect();

Regards
Su


Hi Su,

It’s good to know that ImapClient worked for you in case of Inbox. However, it is strange that you can not get it to work with the items in the Sent folder. I have retested it with the following code sample and a test Gmail account and it’s working fine. Could you please run the following code as it is and share the results with us? We’ll look into it and assist you further.

Sample Code:

ImapClient client = new ImapClient(“imap.gmail.com”, 993, “aetest12”, “f123456f”); 

client.EnableSsl = true;

client.SecurityMode = ImapSslSecurityMode.Implicit;

client.Connect(true);

client.Login();

client.SelectFolder("[Gmail]/Sent Mail");

// Get list of messages

ImapMessageInfoCollection messageInfoCol = client.ListMessages();

Console.WriteLine("Total Messages in Sent:" + messageInfoCol.Count);

foreach (ImapMessageInfo msgInfo in messageInfoCol)

Console.WriteLine("Message Subject: " + msgInfo.Subject);