c# - .Net - Error when get unread mail from Gmail by IMAP protocol -
i'm trying unread mails gmail imap protocol. followed tuto : https://briancaos.wordpress.com/2012/04/24/reading-mails-using-imap-and-mailsystem-net/#comment-4999 , recieved many comments. when call
messagecollection messages = mails.searchparse("unseen");
i got error message "index , length must refer location within string". call simple function, don't know what's wrong. more detail, here code snippet:
public class mailrepository { private imap4client _client = null; public mailrepository(string mailserver, int port, bool ssl, string login, string password) { if (ssl) client.connectssl(mailserver, port); else client.connect(mailserver, port); client.login(login, password); } public ienumerable<message> getallmails(string mailbox) { return getmails(mailbox, "all").cast<message>(); } public ienumerable<message> getunreadmails(string mailbox) { return getmails(mailbox, "unseen").cast<message>(); } protected imap4client client { { if (_client == null) _client = new imap4client(); return _client; } } private messagecollection getmails(string mailbox, string searchphrase) { mailbox mails = client.selectmailbox(mailbox); messagecollection messages = mails.searchparse(searchphrase); return messages; } }
this error may occur when mails contain non-ascii characters. don't see easy fix here , mailsystem.net no longer supported, recommend using alternative library.
mailkit seems option. here further reference: https://stackoverflow.com/a/23375968
Comments
Post a Comment