-1

I am using mailkit on monotouch xamarin. I am creating an app that will receive emails(email client). I give to the user the option to choose if he is using Pop3 or IMAP connection protocol. My issue is that I cant find solution on how he can delete a message on Pop3 and on IMAP. I have tried to use this code:

client.Inbox.AddFlags (new int[] { index }, MessageFlags.Deleted);

from this post: MailKit Delete single message from gmail but is not seems to work for me. My code for capturing the Pop3 acount emails is

using (var client = new Pop3Client ()) {

    var credentials = new NetworkCredential (Convert.ToString (username), Convert.ToString (password));

    var uri = new Uri (Convert.ToString ("pops://"+pop3));

    using (var cancel = new CancellationTokenSource ()) {
        client.Connect (uri, cancel.Token);

        var _emailItems=new List<EmailItem>() ;

        client.Authenticate (credentials, cancel.Token);
        string[] mycell = new string[200];
        int count = client.GetMessageCount (cancel.Token);
        int lastcount;
        for (int i = 0; i < count; i++) {
            lastcount = (count - 1) - i;
            var message = client.GetMessage (lastcount, cancel.Token);
        }
    }
}
Community
  • 1
  • 1
focus
  • 171
  • 9
  • 31

1 Answers1

3

Different protocols have different ways of deleting messages.

For POP3, this is how you would delete a message:

client.DeleteMessage (lastcount, cancel.Token);

(Note: unless you are actually allowing the user to cancel the operations, you do not need to use cancel.Token)

The other way of deleting messages that you pasted is meant for IMAP.

jstedfast
  • 35,744
  • 5
  • 97
  • 110
  • Thank you for your reply. I tried your code but i have not any results. The message doesn't be deleted. When i connected again with the server the message displayed again. – focus Jul 21 '14 at 07:34
  • Are you disconnecting with client.Disconnect (true)? If not, the POP3 server will not actually delete them. – jstedfast Jul 21 '14 at 10:17
  • You are great! yes now it works for me. Can you also help me on how can i delete the message if i use imap? – focus Jul 21 '14 at 10:57
  • The other post you linked to explains how to delete messages with IMAP: http://stackoverflow.com/questions/23677464/mailkit-delete-single-message-from-gmail – jstedfast Jul 21 '14 at 12:25