Example #1
0
        /// <summary>
        /// 获取邮件数据信息,并限定条件
        /// </summary>
        /// <param name="startDate">晚于指定的接收日期的邮件</param>
        /// <param name="endDate">早于指定接收日期的邮件</param>
        /// <param name="titleKeywords">邮件标题中的关键词</param>
        public List <EmailDataInfo> GetMailDataInfos(DateTime?startDate = null, DateTime?endDate = null, String[] titleKeywords = null)
        {
            List <EmailDataInfo> emailDataInfos = new List <EmailDataInfo>();
            List <Mail>          mails          = new List <Mail>();
            List <MailInfo>      mailInfos      = new List <MailInfo>();
            MailServer           oServer        = new MailServer(MailServerAddress,
                                                                 this.User, this.Password, true, ServerAuthType.AuthLogin, ServerProtocol.Imap4);

            oServer.Port = 993;
            MailClient oClient = new MailClient(LicenseCode);

            try
            {
                oClient.Connect(oServer);
                String condition = "ALL";
                if (startDate.HasValue)
                {
                    String startDateStr = this.GetDateString(startDate.Value);
                    condition += " SINCE " + startDateStr;
                }
                if (endDate.HasValue)
                {
                    String endDateStr = this.GetDateString(endDate.Value);
                    condition += " SENTBEFORE " + endDateStr;
                }

                //官网上提供的一系列关键词的条件都无效,暂时使用本地筛选的方法。 https://www.emailarchitect.net/eagetmail/sdk/
                //if (!String.IsNullOrWhiteSpace(titleKeyword))
                //{
                //    condition += $" KEYWORD {titleKeyword}";
                //}

                MailInfo[] result = oClient.SearchMail(condition);
                mailInfos.AddRange(result);
                foreach (var info in mailInfos)
                {
                    //先获取邮件头部信息,此处邮件的信息并不完整,后续需要使用 GetMail 获取完整的邮件信息
                    var headerMailData = oClient.GetMailHeader(info);
                    var headerMail     = new Mail(LicenseCode);
                    headerMail.Load(headerMailData);
                    if (this.AccordTitleKeywords(headerMail.Subject, titleKeywords))
                    {
                        EmailDataInfo dataInfo = new EmailDataInfo();
                        this.BuildEmailDataInfo(dataInfo, headerMail, info);
                        emailDataInfos.Add(dataInfo);
                    }
                }
            }
            finally
            {
                oClient.Quit();
                oClient.Close();
            }
            return(emailDataInfos);
        }
Example #2
0
        /// <summary>
        /// 下载指定的邮件数据信息到本地
        /// </summary>
        /// <param name="dataInfo"></param>
        public void DownloadEmailInfo(EmailDataInfo dataInfo)
        {
            MailServer oServer = new MailServer(MailServerAddress,
                                                this.User, this.Password, true, ServerAuthType.AuthLogin, ServerProtocol.Imap4);

            oServer.Port = 993;
            MailClient oClient = new MailClient(LicenseCode);

            try
            {
                oClient.Connect(oServer);
                var mail = oClient.GetMail(dataInfo.MailInfo);
                this.BuildEmailDataInfo(dataInfo, mail, dataInfo.MailInfo);
                this.SaveMailDataInfo(dataInfo);
                dataInfo.IsDownloadedMail = true;
            }
            finally
            {
                oClient.Quit();
                oClient.Close();
            }
        }
 public void Disconnect()
 {
     oClient.Close();
 }