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); }
/// <summary> /// Default constructor. /// </summary> /// <param name="imap">IMAP client.</param> /// <param name="fetchLine">Initial FETCH response line.</param> /// <param name="handler">Fetch data-items handler.</param> /// <exception cref="ArgumentNullException">Is raised when <b>imap</b>,<b>fetchLine</b> or <b>handler</b> is null reference.</exception> public _FetchResponseReader(IMAP_Client imap,string fetchLine,IMAP_Client_FetchHandler handler) { if(imap == null){ throw new ArgumentNullException("imap"); } if(fetchLine == null){ throw new ArgumentNullException("fetchLine"); } if(handler == null){ throw new ArgumentNullException("handler"); } m_pImap = imap; m_FetchLine = fetchLine; m_pHandler = handler; }