Exemplo n.º 1
0
 private void Init()
 {
     BLL.SettingBLL bll = new BLL.SettingBLL();
     Dictionary<string, string> dic = bll.GetMailSet();
     tbPOP.Text = dic["POP"];
     tbPort.Text = dic["Port"];
     tbMail.Text = dic["Mail"];
     tbMailPwd.Password = dic["MailPwd"];
     tbKeyword.Text = dic["Keyword"];
 }
Exemplo n.º 2
0
        public static void ReceiveMails(System.ComponentModel.BackgroundWorker backgroundWorker)
        {
            string pop, port, mailname, mailpassword, keyword;
            try
            {
                BLL.SettingBLL bll = new BLL.SettingBLL();
                Dictionary<string, string> dic = bll.GetMailSet();
                pop = dic["POP"];
                port = dic["Port"];
                mailname = dic["Mail"];
                mailpassword = dic["MailPwd"];
                keyword = dic["Keyword"];

                if (pop3Client.Connected)
                    pop3Client.Disconnect();
                pop3Client.Connect(pop, int.Parse(port), true);
                pop3Client.Authenticate(mailname, mailpassword);
                int count = pop3Client.GetMessageCount();

                for (int i = 1; i <= count; i++)
                {
                    backgroundWorker.ReportProgress((int)(((double)i / count) * 100));
                    /*
                    * 1.接收邮件,筛选出带有关键字开头的邮件
                    * 2.将邮件格式转成xaml便于读取
                    * 3.判断邮件时间,如果当天邮件则进行合并和显示操作;如果是以前的时间,就进行合并和保存操作
                    * 4.删除已读取的邮件
                    */
                    Message message = pop3Client.GetMessage(i);
                    if (message.Headers.Subject.StartsWith(keyword))
                    {
                        SaveMail(i, message);
                        pop3Client.DeleteMessage(i);
                        continue;
                    }
                }

            }
            catch
            {
                return;
            }
            //提交删除的更改信息
            TryMail(pop, port, mailname, mailpassword);
        }