コード例 #1
0
ファイル: ReceiveFacade.cs プロジェクト: demon28/NSMPT
        private bool InsertAttTable(MimeEntity entity, Tnsmtp_Account tnsmtp_Account, Tnsmtp_Recmail tnsmtp_Recmail)
        {
            string    url       = string.Empty;
            ImapEmail imapEmail = new ImapEmail();

            if (!imapEmail.KitAttFileHelper(entity, tnsmtp_Account.Userid, out url))
            {
                Log.Info("文件下载失败!" + entity.ContentDisposition.FileName);
                Alert("文件下载失败");
                return(false);
            }


            DataAccess.Tnsmtp_Receivefile tnsmtp_Receivefile = new Tnsmtp_Receivefile();

            tnsmtp_Receivefile.ReferenceTransactionFrom(this.Transaction);

            tnsmtp_Receivefile.RecMailid   = tnsmtp_Recmail.Recid;
            tnsmtp_Receivefile.Userid      = tnsmtp_Recmail.Recid;
            tnsmtp_Receivefile.Accountid   = tnsmtp_Account.Aid;
            tnsmtp_Receivefile.Fileurl     = url;
            tnsmtp_Receivefile.Filename    = entity.ContentDisposition.FileName;
            tnsmtp_Receivefile.Downloadurl = "/File/UserFile/" + tnsmtp_Account.Userid + "/RecAttachment/" + Path.GetFileName(url);

            FileInfo fileInfo = new FileInfo(url);

            tnsmtp_Receivefile.Filesize = (int)Math.Ceiling(fileInfo.Length / 1048576.0);

            if (!tnsmtp_Receivefile.Insert())
            {
                Log.Info("获取邮件后添加附件失败!" + entity.ContentDisposition.FileName);
                Alert("添加附件信息失败");
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: ReceiveFacade.cs プロジェクト: demon28/NSMPT
        /// <summary>
        /// 刷新获取邮件更新
        /// </summary>
        /// <param name="accountId"></param>
        /// <returns></returns>
        public bool GetAccountEmail(int accountId)
        {
            DateTime?beforeDate = null;

            DataAccess.Tnsmtp_Account tnsmtp_Account = new DataAccess.Tnsmtp_Account();

            if (!tnsmtp_Account.SelectByPK(accountId))
            {
                Log.Info("获取邮件账户信息错误");
                return(false);
            }

            Tnsmtp_Mailtype tnsmtp_Mailtype = new Tnsmtp_Mailtype();

            if (!tnsmtp_Mailtype.SelectByPK(tnsmtp_Account.MailType))
            {
                Log.Info("获取邮件配置失败");
                Alert("获取邮件配置失败!");
                return(false);
            }

            Tnsmtp_Recmail tnsmtp_Recmail = new Tnsmtp_Recmail();

            if (tnsmtp_Recmail.SelectMaxRecEmail(accountId, tnsmtp_Account.Userid))
            {
                beforeDate = tnsmtp_Recmail.Rectimer;
            }
            List <MimeKit.MimeMessage> messages = new List <MimeKit.MimeMessage>();

            ImapEmail imap = new ImapEmail();

            if (!imap.KitEmailHelper(tnsmtp_Mailtype.PopUrl, tnsmtp_Mailtype.PopPort, tnsmtp_Account.Account, tnsmtp_Account.Password, beforeDate, out messages))
            {
                Log.Info("获取邮件失败");
                Alert("获取邮件失败!");
                return(false);
            }

            if (messages.Count <= 0)
            {
                Log.Info("没有信息的邮件");
                Alert("没有信息的邮件!");
                return(true);
            }


            BeginTransaction();

            foreach (MimeMessage item in messages)
            {
                if (!InserRecTable(item, tnsmtp_Account))
                {
                    Log.Info("添加收件箱失败");
                    Alert("获取邮件失败!");
                    Rollback();
                    return(false);
                }
            }
            Commit();
            return(true);
        }