Example #1
0
        /// <summary>
        /// 异步是要等待消费者的回复
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public Task <PFEmail> BuildPFEmailMqProducerAsync(String message)
        {
            var rt = new Task <PFEmail>(() =>
            {
                var UserEmailUserName = PFDataHelper.SysEmailUserName;
                var UserEmailPwd      = PFDataHelper.SysEmailPwd;
                var UserEmailHostName = PFDataHelper.SysEmailHostName;


                //生产方监听回复
                PFEmail result    = null;
                bool hasGotResult = false;
                var st            = DateTime.Now;
                //var nowStr = DateTime.Now.ToString(PFDataHelper.DateFormat);
                var producerListenTask = new PFListenEmailTask("PFEmailMqProducerListener_" + _mqConfig.getTopic(),
                                                               new PFEmailManager(UserEmailHostName, UserEmailUserName, UserEmailPwd),
                                                               email =>
                {
                    result       = email;
                    hasGotResult = true;
                },
                                                               (email//, task
                                                               ) =>
                {
                    return(email.Subject == "PFEmailMq_consumer_Response_" + _mqConfig.getTopic() + message);
                }, true);
                producerListenTask.Start();

                //Thread.Sleep(2000);//不延迟的话,后面太快了,前面还没开始监听(其实没问题,因为_lastListenTime是在PFListenEmailTask初始化时就赋值了
                ////生产方发邮件
                BuildPFEmailMqProducer(message);
                //PFDataHelper.SendEmail(UserEmailUserName, UserEmailPwd, UserEmailHostName,
                //    new string[] { PFDataHelper.SysEmailUserName },
                //    _mqConfig.getTopic(), message);

                while (!hasGotResult)
                {
                    if ((DateTime.Now - st).TotalHours > 1)
                    {
                        producerListenTask.Dispose();
                        result         = new PFEmail();
                        result.Subject = "消费者超过1小时没有响应";
                        break;
                    }
                    Thread.Sleep(2000);
                }
                producerListenTask.NaturalStop();
                return(result);
            });

            rt.Start();
            return(rt);
        }
Example #2
0
        public void TestSendEmail()
        {
            PFDataHelper.SendEmail(UserEmailUserName, UserEmailPwd, UserEmailHostName,
                                   new string[] { PFDataHelper.SysEmailUserName },
                                   "aaa", "aaaaa");
            return;

            string emailTitle = "test_PFEmailMq_producer_会员资料表";//中文有问题--benjamin todo
            //string emailBody = "会员资料表";
            //string emailBody = "hyzlTable_aabb_中国人";
            string emailBody = @"
<p>2019.01月结数据备份情况:<p>
<ol>
<li>aaa</li>
<li>bbb</li>
</ol>
";
            //string producerEmailTitle = "PFEmailMq_producer_" + "hyzl";
            //消费方(使用系统邮箱)
            PFEmail result       = null;
            bool    success      = false;
            var     consumerTask = new PFListenEmailTask("TestForceUpdateHyzl",
                                                         new PFEmailManager(PFDataHelper.SysEmailHostName, PFDataHelper.SysEmailUserName, PFDataHelper.SysEmailPwd),
                                                         email =>
            {
                result  = email;
                success = true;
            },
                                                         (email//, task
                                                         ) =>
            {
                return(email.Subject == emailTitle);
            });

            consumerTask.Start();

            //生产方(使用User邮箱,也可以用系统邮箱吧)
            var rt = new Task(() =>
            {
                PFDataHelper.SendEmail(UserEmailUserName, UserEmailPwd, UserEmailHostName,
                                       new string[] { PFDataHelper.SysEmailUserName },
                                       emailTitle, emailBody);
            });

            rt.Start();
            rt.Wait();
            while (!success)
            {
                Thread.Sleep(2000);
            }
            Assert.IsTrue(emailTitle == result.Subject);
        }
        ///// <summary>
        ///// 运行时要读昨天的邮件(之后不匹配)
        ///// </summary>
        //private void ReadEmailAtYesterday()
        //{
        //    _emailManager.Connect_Click();
        //    for (int i = _emailManager.MessageCount; i > 0; i--)
        //    {
        //        var email = _emailManager.Retrieve_Click(i);
        //        if (email != null && email.Date != null )
        //        {
        //            if(email.Date >= _lastListenTime.AddDays(-1))
        //            {
        //                _emailAtToday.Add(email);
        //            }else
        //            {
        //                break;
        //            }
        //        }else
        //        {
        //            throw new Exception("监听邮件失败,ReadEmailAtYesterday报错");
        //        }
        //    }
        //    _emailManager.Disconnect_Click();
        //}
        #region 存在漏洞,有时MessageCount比较大时,邮件时间反而小--benjamin20200413
        public void StartThread(object ps)
        {
            PFEmail email = null;

            while (_running == true)
            {
                try
                {
                    //try
                    //{
                    //    //为了检查26服务器上监听邮件失效的问题--benjamin
                    //    PFDataHelper.WriteLocalTxt(string.Format("监听邮件的while进行中,时间:{0}", DateTime.Now.ToString()), "PFListenEmailTask_while.txt");
                    //}
                    //catch (Exception) { }

                    //if (PFDataHelper.IsDebug)
                    //{
                    //    PFDataHelper.WriteLog("1");
                    //}
                    _emailManager.Connect_Click();
                    if (!_emailManager.IsConnect())  //Connect_Click的new TcpClient(_hostName, 110) 是有可能连接失败的--benjamin20200318
                    {
                        Thread.Sleep(1000 * 60 * 5); //如果连接失败,等5分钟
                        continue;
                    }

                    try
                    {
                        //为了检查26服务器上监听邮件失效的问题--benjamin todo
                        PFDataHelper.WriteLocalTxt(string.Format("监听邮件的while的_emailManager.Connect_Click()执行成功,时间:{0},邮件数:{1}", DateTime.Now.ToString(), _emailManager.MessageCount), "PFListenEmailTask_while_Connect_Click.txt");
                    }
                    catch (Exception) { }

                    DateTime?newestMailTime = null; //记录最新邮件的时间
                                                    //bool hasMatch = false;
                                                    //PFDataHelper.WriteLog("MessageCount:" + _emailManager.MessageCount);
                                                    //if (PFDataHelper.IsDebug)
                                                    //{
                                                    //    PFDataHelper.WriteLog("2");
                                                    //    //PFDataHelper.WriteLocalTxt(string.Format("时间{0}\r\nMessageCount:{1}",DateTime.Now, _emailManager.MessageCount), "listenEmail_Connect_Click.txt");
                                                    //}
                    bool isAnyReceiveFail = false;
                    for (int i = _emailManager.MessageCount; i > 0; i--)
                    {
                        //if (PFDataHelper.IsDebug)
                        //{
                        //    PFDataHelper.WriteLog("3");
                        //}
                        email = _emailManager.Retrieve_Click(i);//System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. --benjamin

                        try
                        {
                            //为了检查26服务器上监听邮件失效的问题--benjamin todo
                            PFDataHelper.WriteLocalTxt(string.Format("监听邮件的while的_emailManager.Retrieve_Click()执行成功,时间:{0},邮件数:{1}", DateTime.Now.ToString(), _emailManager.MessageCount), "PFListenEmailTask_while_Retrieve_Click.txt");
                        }
                        catch (Exception) { }

                        //if (PFDataHelper.IsDebug)
                        //{
                        //    PFDataHelper.WriteLog("4");
                        //}
                        if (email == null)
                        {
                            //为了解决这个漏洞:
                            //当第一个邮件能收到,那newestMailTime变成它的时间,但后面的都接收失败了,那么下次就会永远读不到那个失败的邮件
                            newestMailTime   = null;
                            isAnyReceiveFail = true;
                            continue;
                        }//这里不用break是防止id有中间非连续的情况--benjamin20190929

                        if (i == _emailManager.MessageCount)
                        {
                            newestMailTime = email.Date;
                        }

                        //if (email.Date <= _lastListenTime)
                        //if (email.Date != null && _lastListenTime != null &&
                        //    email.Date.Value.AddMinutes(2) < _lastListenTime) //这里用等号似乎会有问题,有时生产者发的邮件时间反而大于消费者回复的邮件的时间(可能邮件上的时间是根据发送端的电脑时间来的,有误差),可能有更好的方法可以统一时间?--benjamin todo
                        //为解决邮件id大但邮件时间反而小的问题
                        if (email.Date != null)
                        {
                            if (email.Date <= _lastListenTime.AddDays(-1)) //昨天的邮件直接不读
                            {
                                email.Dispose();
                                break;
                            }
                            else if (email.Date <= _lastListenTime)          //今天的邮件
                            {
                                if (_emailAtToday.Any(a => a.Equals(email))) //今天的邮件要比对
                                {
                                    email.Dispose();
                                    //continue;
                                    break;
                                }
                                else
                                {
                                    _emailAtToday.Add(email);
                                    if (email.Date < _initTime.AddMinutes(-1))
                                    {
                                        email.Dispose();
                                        break;
                                    }
                                }
                            }
                            else //新邮件(没有这句的话,新邮件会读两次--benjamin20200414
                            {
                                if (!_emailAtToday.Any(a => a.Equals(email)))
                                {
                                    _emailAtToday.Add(email);
                                }
                            }
                        }
                        else
                        {
                            isAnyReceiveFail = true;
                        }
                        //if (PFDataHelper.IsDebug)
                        //{
                        //    PFDataHelper.WriteLog("7");
                        //}

                        var b = false;
                        try
                        {
                            b = SubjectMatch(email);
                        }
                        catch (Exception e)
                        {
                            newestMailTime = null;
                            PFDataHelper.WriteError(new Exception(string.Format("SubjectMatch报错{0}", e)));
                        }
                        if (b)
                        {
                            try
                            {
                                _emailManager.Disconnect_Click();

                                DoAction(email);
                            }
                            catch (Exception e)
                            {
                                PFDataHelper.WriteError(e);
                            }
                            email.Dispose();
                            ////_emailManager.DeleteEmail(email);
                            //_lastListenTime = email.Date ?? DateTime.Now;
                            if (_onlyListenOnce)
                            {
                                _running = false;
                                return;
                            }
                            break;
                        }

                        email.Dispose();
                    }
                    //if (PFDataHelper.IsDebug)
                    //{
                    //    PFDataHelper.WriteLog("11");
                    //}
                    //不管有没有匹配到邮件,下次都应该找时间更新的邮件了
                    if (newestMailTime != null && newestMailTime > _lastListenTime && (!isAnyReceiveFail))
                    {
                        _lastListenTime = newestMailTime.Value;
                    }

                    //if (PFDataHelper.IsDebug)
                    //{
                    //    PFDataHelper.WriteLog("12");
                    //}
                    _emailManager.Disconnect_Click();
                    //if (PFDataHelper.IsDebug)
                    //{
                    //    PFDataHelper.WriteLog("13");
                    //}
                    Thread.Sleep(CheckMessageInterval);
                    //if (PFDataHelper.IsDebug)
                    //{
                    //    PFDataHelper.WriteLog("14");
                    //}
                    GC.Collect();//一定要有句,否则SendMobileMessage里面的所有List会使内存越来越高

                    //if (PFDataHelper.IsDebug)
                    //{
                    //    PFDataHelper.WriteLog("15");
                    //}

                    RemoveEmailAtYesterday();
                }
                catch (Exception e)
                {
                    PFDataHelper.WriteError(e);
                    Thread.Sleep(CheckMessageInterval);
                }
            }
        }
Example #4
0
        public void TestEmail()
        {
            PFEmail email   = null;
            string  subject = null;
            string  body    = null;



            //var message = JsonConvert.DeserializeObject<List<string>>(PFDataHelper.ReadLocalTxt("mailFujianJson.txt"));
            //email = new PFEmail(message);
            //body = email.Body;
            ////return;
            //Assert.IsTrue(body == "各们领导、同事:\r\n\r\n       附件为油葱架构文档V1.5版,请查收,谢谢\r\n\r\n \r\n\r\n \r\n\r\n陈辉\r\n\r\n");

            List <KeyValuePair <string, KeyValuePair <string, string> > > fileNames = new List <KeyValuePair <string, KeyValuePair <string, string> > > {
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "126Email.txt", new KeyValuePair <string, string>(
                        "PFEmailMq_producer_from126Mail_会员资料表",
                        "2019.01月结数据备份情况:\n\naaa\nbbb\n\n")),
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "aliyunEmail.txt", new KeyValuePair <string, string>(
                        "[SPAM]PFEmailMq_producer_fromSellGirl_会员资料表",
                        "\n<p>2019.01月结数据备份情况:<p>\n<ol>\n<li>aaa</li>\n<li>bbb</li>\n</ol>")),
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "perfect99Email.txt", new KeyValuePair <string, string>(
                        "PFEmailMq_producer_会员资料表",
                        "\r\n<p>2019.01月结数据备份情况:<p>\r\n<ol>\r\n<li>aaa</li>\r\n<li>bbb</li>\r\n</ol>\r\n")),
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "perfect99Email_含附件.txt", new KeyValuePair <string, string>(
                        "油葱架构文档V1.5版",
                        "各们领导、同事:\r\n\r\n       附件为油葱架构文档V1.5版,请查收,谢谢\r\n\r\n \r\n\r\n \r\n\r\n陈辉\r\n\r\n")),
                #region qqEmail
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "qqEmail.txt", new KeyValuePair <string, string>(
                        "PFEmailMq_producer_fromQQMail_会员资料表",
                        "2019.01月结数据备份情况:\r\n\r\n \r\n \r\naaa\r\n \r\nbbb")),
                #endregion qqEmail
                #region perfect99Email2
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "perfect99Email2.txt", new KeyValuePair <string, string>(
                        "转发: Fw: 请示",
                        @"



[email protected]
 
发件人: 完美(中国)有限公司 信息中心
发送时间: 2020-04-13 16:15
收件人: 王现伟
抄送: 余凤瑜
主题: Fw: 请示
王现伟,您好! 
 
  
 
 
= = = = = = 下面是转发邮件 = = = = = = =

原邮件发件人名字:胡文祥
原邮件发件人地址:[email protected]
原邮件收件人名字:王天庆总监; 李观棉
原邮件收件人地址:[email protected]; [email protected]
原邮件抄送人名字:
原邮件抄送人地址:

信息中心,您好!
我部2020年2月19日已取消购买宜悦空气净化器优惠购(AP60025)获得800元奖励的活动。后因服务中心库存较多,经过请示领导特将服务中心后台报单时间调整至3月31日。请继续提取空机(AP60025)2月及3月的实际销售名单给到财务以发放相应补贴:

请同步发一份销售名单给到此邮箱号([email protected])谢谢!    附:补报返现补贴的请示


胡文祥(推广专员)
市场中心 -策划部 
TEL:0760-88701828-88225/13924995602
E-Mail :[email protected]

完美(中国)有限公司  Perfect (China) Co., Ltd.
地址:广东省中山市石岐区东明北路(民营科技园),邮编:528402
Add :Dongming North Road, Shiqi District, Zhongshan
City, Guangdong Province, PRC (528400


= = = = = = = = = = = = = = = = = = = = 
        致
礼! 
                          完美(中国)有限公司 信息中心
                          [email protected]
                          2020-04-13
              
")),
                #endregion perfect99Email2

                #region perfect99Email3
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "perfect99Email3.txt", new KeyValuePair <string, string>(
                        "Fw: 关联关系申报与处理规定签订事宜Message-ID: <*****@*****.**>Organization: =?gb2312?B?zerDwKOo1tC5+qOp09DP3rmry74=?=X-mailer: Foxmail 6, 15, 201, 20 [cn]",
                        @"陈超,您好! 

  


= = = = = = 下面是转发邮件 = = = = = = =

原邮件发件人名字:人力资源中心
原邮件发件人地址:[email protected]

原邮件收件人名字:财务中心; 采购中心; 法务外事中心; 供应商改造项目组; 基建办; 集团战略法务部; 监察中心; 健康公司工作小组; 企业门户项目组; 人力资源中心; 市场中心; 完美大学; 信息中心; 研发中心; 业务中心; 制造中心; 总裁办; 董事长助理徐奕新高级经理; 董事长秘书陈嘉丽; 许生秘书许丽萍; 董事会办公室江晓君; 董事长助理秘书-柯冬燕; 董事长秘书张子卉; 副董事长办-赖丽霞; 副董事长秘书-黄学军; 常务副总裁秘书黄绮柔; 总裁办黄思苑; 分子机构管理室; 扬州人力资源部
原邮件收件人地址:[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
原邮件抄送人名字:
原邮件抄送人地址:

各中心/部门:
     您好!
     为了进一步完善个人信息申报体系,有效管控公司与个人的利益冲突,公司制定了《关联关系申报与处理规定》及相应申报表,现请各位员工按以下要求完成相关申报:
   
      一、申报对象:文员级及以上级别员工(名单单独发各中心秘书)。
   
     二、提交要求:
     A、总部、完美广东员工需在4月16日下午16:00前,将《关联关系申报与处理规定》、《关联关系申报表》签字版原件以中心为单位提交至人力资源中心王成 
瑶处(IP:88390)。
     B、分公司员工需在4月16日下午16:00前将签字版原件寄至人力资源中心黄燕婵收(请勿与其他资料混在一起)。
     C、扬州完美人员由扬州完美人力资源部负责收集汇总与存档,其中经理级及以上员工的《关联关系申报与处理规定》、《关联关系申报表》扫描件,由扬州人力资源部扫描后发至:[email protected]。
   
     三、填写要求:
     A、申报内容可以打印,必须按“申报要求”将相关内容填写完整。
     B、规定签名处及申报表的签名处必须亲笔签名,且正楷字清晰签署。
     C、规定与申报表可双面打印,两面均需按要求签名。


    以上请知悉配合,如有疑问,请与谭富豪(88389)/王成瑶(88390)联系。谢谢!

2020-04-13



祝工作顺利!

       致

  礼!
 
  人力资源中心  HR CENTER
 Tel:88701828-88392 方玉英
 Fax:88701828-88370





= = = = = = = = = = = = = = = = = = = = 
        致
礼! 
                          完美(中国)有限公司 信息中心
                          [email protected]
                          2020-04-13
              
")),
                #endregion perfect99Email3

                #region perfect99Email4
                new KeyValuePair <string, KeyValuePair <string, string> >(
                    "perfect99Email4.txt", new KeyValuePair <string, string>(
                        "新电子商务系统权限申请_0603015",
                        @"<p>新电子商务系统权限申请</p>
<p>申请人工号:0603015</p>
")) //,
                #endregion perfect99Email4
            };

            //fileNames = fileNames.Where(a => a.Key == "perfect99Email4.txt").ToList();
            foreach (var i in fileNames)
            {
                //email = new PFEmail(PFDataHelper.ReadLocalTxt(i).Split(new char[] { '\r', '\n' }));
                try
                {
                    email   = new PFEmail(PFDataHelper.ReadLocalTxt(i.Key).Split(new string[] { "\r\n" }, StringSplitOptions.None));
                    subject = email.Subject;
                    //PFDataHelper.WriteLog(subject);
                    body = email.Body;
                }
                catch (Exception e)
                {
                    throw new Exception(i.Key + e.ToString());
                }
                if (subject != i.Value.Key || body != i.Value.Value)
                {
                    throw new Exception(i.Key);
                }
                //Assert.IsTrue(body == i.Value);
            }

            var aa = "aa";
        }
Example #5
0
 public PFMqMessage(PFEmail email)
 {
     message = email.Body;
 }