Esempio n. 1
0
        public override void init()
        {
            using (IMAP_Client imap = new IMAP_Client())
            {
                imap.Connect(m_host, m_port);
                imap.Capability();
                imap.Login(m_user, m_pwd);

                var seqSet = LumiSoft.Net.IMAP.IMAP_t_SeqSet.Parse("1:*");
                var imap_t_Fetch_i = new IMAP_t_Fetch_i[]{
                         new IMAP_t_Fetch_i_Envelope(),//邮件的标题、正文等信息
                         new IMAP_t_Fetch_i_Flags(),//此邮件的标志,应该是已读未读标志
                         new IMAP_t_Fetch_i_InternalDate(),//貌似是收到的日期
                         new IMAP_t_Fetch_i_Rfc822(),//Rfc822是标准的邮件数据流,可以通过Lumisoft.Net.Mail.Mail_Message对象解析出邮件的所有信息(不确定有没有附件的内容)。
                         new IMAP_t_Fetch_i_Uid()
                };

                imap.SelectFolder("INBOX");
                EventHandler<LumiSoft.Net.EventArgs<IMAP_r_u>> lumisoftHandler = new EventHandler<LumiSoft.Net.EventArgs<IMAP_r_u>>(Fetchcallback);
                imap.Fetch(false, seqSet, imap_t_Fetch_i, lumisoftHandler);
            }
        }
Esempio n. 2
-1
        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);
        }