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);
}
}
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.