public bool SendMail(string title, string content)
        {
            string      useremail = mConfig.UserMailID;
            string      password  = mConfig.UserMailPassword;
            string      to        = mConfig.ToMail;
            MailMessage msg       = new MailMessage(useremail, to);

            msg.Subject         = title;
            msg.Body            = content;
            msg.IsBodyHtml      = false;
            msg.BodyEncoding    = System.Text.Encoding.GetEncoding("UTF-8");
            msg.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            msg.Priority        = MailPriority.Normal;
            SmtpClient client = new SmtpClient();

            string[] usernameAndHost = useremail.Split('@');
            string   host            = "smtp." + usernameAndHost[1];
            string   uname           = usernameAndHost[0];

            client.Host = host;
            client.UseDefaultCredentials = false;
            client.Credentials           = new System.Net.NetworkCredential(uname, password);
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            try {
                client.Send(msg);
                LogWrapper.LogError("邮件发送成功:");
                return(true);
            } catch (Exception e) {
                LogWrapper.LogError("邮件发送失败:" + e.Message);
            }

            return(false);
        }
Пример #2
0
        void HandleSubmitpaper(Carapplyarr carinfo)
        {
            var enterBjStart = DateTime.Now.AddDays(1);

            LogWrapper.LogInfoFormat("正在申请进京证 进京日期 {0} 进京时间 {1} 天", enterBjStart.ToString("yyyy-MM-dd"), mConfig.InbjDuration);
            State = RunState.WaitingNet;
            JinJingZhengAPI.Submitpaper(mConfig.UserID, mConfig.InbjDuration, enterBjStart, carinfo.licenseno, carinfo.engineno, mConfig.CarTypeCode,
                                        mConfig.VehicleType, Image.FromFile(mConfig.DrivingPhoto),
                                        Image.FromFile(mConfig.CarPhoto),
                                        mConfig.DriverName,
                                        mConfig.DriverLicenseno,
                                        Image.FromFile(mConfig.DriverPhoto),
                                        Image.FromFile(mConfig.PersonPhoto),
                                        carinfo.carid,
                                        mConfig.CarModel,
                                        mConfig.CarRegTime,
                                        (result, ex) => {
                if (ex == null)
                {
                    string rescode = result["rescode"].ToString();
                    string resdes  = result["resdes"].ToString();
                    if (rescode == "200")
                    {
                        LogWrapper.LogInfo("进京证申请成功,正在审核中.");
                        if (SendMail("进京证申请成功,正在审核" + carinfo.licenseno, enterBjStart.ToString("yyyy-MM-dd") + " " + mConfig.InbjDuration + "天"))
                        {
                            LogWrapper.LogInfo("提醒邮件发送成功...");
                        }
                        else
                        {
                            LogWrapper.LogInfo("提醒邮件发送失败...");
                        }
                    }
                    else
                    {
                        LogWrapper.LogError(string.Format("申请进京证失败.错误码:{0} 错误信息:{1}", rescode, resdes));
                        SendMail("进京证申请失败:" + rescode, resdes);
                    }
                }
                else
                {
                    HandleError("申请进京证失败,网络异常", ex);
                }

                State = RunState.Waiting;
            });
        }
        /// <summary>
        /// 申请进京证
        /// </summary>
        /// <param name="carinfo">车辆信息</param>
        /// <param name="pic_str">验证码文本</param>
        /// <param name="pic_id">验证码图片ID</param>
        void HandleSubmitpaper(Carapplyarr carinfo, string pic_str, string pic_id)
        {
            var enterBjStart = DateTime.Now.AddDays(1);

            LogWrapper.LogInfoFormat("正在申请进京证 进京日期 {0} 进京时间 {1} 天", enterBjStart.ToString("yyyy-MM-dd"), mConfig.InbjDuration);
            State = RunState.WaitingNet;
            api.Submitpaper(mConfig.UserID, mConfig.InbjDuration, enterBjStart, carinfo.licenseno, carinfo.engineno, mConfig.CarTypeCode,
                            mConfig.VehicleType, Image.FromFile(mConfig.DrivingPhoto),
                            Image.FromFile(mConfig.CarPhoto),
                            mConfig.DriverName,
                            mConfig.DriverLicenseno,
                            Image.FromFile(mConfig.DriverPhoto),
                            Image.FromFile(mConfig.PersonPhoto),
                            carinfo.carid,
                            mConfig.CarModel,
                            mConfig.CarRegTime,
                            pic_str,
                            (result, ex) => {
                var ret = result as JObject;
                if (ex == null)
                {
                    string rescode = ret["rescode"].ToString();
                    string resdes  = ret["resdes"].ToString();
                    if (rescode == "200")
                    {
                        LogWrapper.LogInfo("进京证申请成功,正在审核中.");
                        if (SendMail("进京证申请成功,正在审核" + carinfo.licenseno, enterBjStart.ToString("yyyy-MM-dd") + " " + mConfig.InbjDuration + "天"))
                        {
                            LogWrapper.LogInfo("提醒邮件发送成功...");
                        }
                        else
                        {
                            LogWrapper.LogInfo("提醒邮件发送失败...");
                        }
                    }
                    else
                    {
                        LogWrapper.LogError(string.Format("申请进京证失败.错误码:{0} 错误信息:{1}", rescode, resdes));
                        SendMail("进京证申请失败:" + rescode, resdes);
                        if (resdes.Contains("验证码错误"))
                        {
                            // 验证码错误
                            LogWrapper.LogInfo("正在向超级鹰报告验证码错误信息...");
                            //try {
                            //    string str = NetRecognizePic.CJY_ReportError(mConfig.CJYUsername, Utils.MD5String(mConfig.CJYPassword), pic_id, "96001");
                            //    JObject reportError = JObject.Parse(str);
                            //    string err_no = reportError["err_no"].ToString();
                            //    string err_str = reportError["err_str"].ToString();
                            //    if (err_no == "0") {
                            //        LogWrapper.LogInfo("向超级鹰报告验证码错误信息成功!");
                            //    } else {
                            //        LogWrapper.LogInfo("向超级鹰报告验证码错误信息失败:" + err_str);
                            //    }
                            //} catch {
                            //    LogWrapper.LogInfo("向超级鹰报告验证码错误信息时,发生错误!");
                            //}

                            // 继续识别验证码
                            //HandleCaptcha(carinfo);
                        }
                    }
                }
                else
                {
                    HandleError("申请进京证失败,网络异常", ex);
                }

                State = RunState.Waiting;
            });
        }
 void HandleError(string prefix, System.Exception ex)
 {
     LogWrapper.LogError(prefix + ":" + ex.Message);
     State = RunState.Waiting;
 }