private string GetSeqSet() { switch (_criteria) { case SeqSetCriteriaEnum.SaveNo: return(_savedSeqNo + ":*"); case SeqSetCriteriaEnum.Unseen: var unseenIds = _client.Search(false, Encoding.UTF8, new IMAP_Search_Key_Unseen()); return(string.Join(",", unseenIds)); case SeqSetCriteriaEnum.Handle: return(_seqSet); case SeqSetCriteriaEnum.Recent: var recentIds = _client.Search(false, Encoding.UTF8, new IMAP_Search_Key_Recent()); return(string.Join(",", recentIds)); default: var defaultIds = _client.Search(false, Encoding.UTF8, new IMAP_Search_Key_Unseen()); return(string.Join(",", defaultIds)); } }
public void getEmail(string login, string password) { IMAP_Client client = new IMAP_Client(); client.Connect("imap.yandex.ru", 993, true); client.Login(login, password); client.SelectFolder("INBOX"); IMAP_SequenceSet sequence = new IMAP_SequenceSet(); //sequence.Parse("*:1"); // from first to last IMAP_Client_FetchHandler fetchHandler = new IMAP_Client_FetchHandler(); fetchHandler.NextMessage += new EventHandler(delegate(object s, EventArgs e) { Console.WriteLine("next message"); }); fetchHandler.Envelope += new EventHandler <EventArgs <IMAP_Envelope> >(delegate(object s, EventArgs <IMAP_Envelope> e) { IMAP_Envelope envelope = e.Value; if (envelope.From != null && !String.IsNullOrWhiteSpace(envelope.Subject)) { Console.WriteLine(envelope.Subject); } }); // the best way to find unread emails is to perform server search int[] unseen_ids = client.Search(false, "UTF-8", "unseen"); Console.WriteLine("unseen count: " + unseen_ids.Count().ToString()); // now we need to initiate our sequence of messages to be fetched sequence.Parse(string.Join(",", unseen_ids)); // fetch messages now client.Fetch(false, sequence, new IMAP_Fetch_DataItem[] { new IMAP_Fetch_DataItem_Envelope() }, fetchHandler); // uncomment this line to mark messages as read // client.StoreMessageFlags(false, sequence, IMAP_Flags_SetType.Add, IMAP_MessageFlags.Seen); }