Example #1
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="dataTable"></param>
        private void SendMail(List <ProductSaleInfo> entities)
        {
            string      dateString = DateTime.Now.Date.Year.ToString() + "-" + DateTime.Now.Date.Month.ToString() + "-" + DateTime.Now.Date.Day.ToString();
            MailInfo    mail       = new MailInfo();
            ExcelManage excelm     = new ExcelManage();

            string filePath = excelm.WriteToFile(entities);

            mail.FromName   = Settings.EmailFrom;
            mail.ToName     = Settings.EmailAddress;
            mail.Subject    = Settings.MailSubject + DateTime.Now.Date.ToShortDateString();
            mail.Body       = Settings.MailBody;
            mail.IsHtmlType = false;

            mail.Attachments = new List <string>();
            mail.Attachments.Add(filePath);
            mail.IsAsync    = false;
            mail.IsInternal = true;

            try
            {
                MailHelper.SendEmail(mail);
                MailDA.SendEmail(mail.ToName, mail.Subject, mail.Body, 1);
            }
            catch
            {
                MailDA.SendEmail(mail.ToName, mail.Subject, mail.Body, -1);
            }
        }
Example #2
0
        public Dictionary <string, bool?> GetBatchMailStatus(List <string> messageIDs)
        {
            if (messageIDs == null)
            {
                return(null);
            }

            var key = string.Format(Sessionkey_IsCloseMailPage, messageIDs[0]);
            var dic = new Dictionary <string, bool?>();

            if (HttpContext.Current.Session[key] != null && (bool)HttpContext.Current.Session[key])
            {
                foreach (var id in messageIDs)
                {
                    dic[id] = false;
                }
            }
            else
            {
                foreach (var id in messageIDs)
                {
                    var val = MailDA.GetMailStatus(id);
                    if (val)
                    {
                        dic[id] = true;
                    }
                    else
                    {
                        dic[id] = null;
                    }
                }
            }
            return(dic);
        }
Example #3
0
        public void SendCustomeReport()
        {
            CustomerInfoDal     dal  = new CustomerInfoDal();
            List <CustomerInfo> list = dal.GetCustomerInfo();

            ExcelManage excel     = new ExcelManage();
            string      excelFile = excel.WriteExcel(list);


            MailInfo mailInfo = new MailInfo
            {
                FromName    = Settings.EmailFrom,
                ToName      = Settings.EmailAddress,
                CCName      = Settings.MailCC,
                Subject     = Settings.MailSubject,
                Body        = Settings.MailBody,
                IsAsync     = false,
                IsInternal  = true,
                Attachments = new List <string>()
            };

            mailInfo.Attachments.Add(excelFile);
            bool isuccess = MailHelper.SendEmail(mailInfo);

            if (isuccess)
            {
                MailDA.SendEmail(Settings.EmailAddress, Settings.MailSubject, Settings.MailBody, 1);
            }
            else
            {
                MailDA.SendEmail(Settings.EmailAddress, Settings.MailSubject, Settings.MailBody, -1);
            }
        }
Example #4
0
 /// <summary>
 /// 更新MailMessage的状态
 /// </summary>
 /// <param name="messageID"></param>
 /// <param name="isSent"></param>
 public static void UpdateMailMessage(MailMessage message)
 {
     if (message != null)
     {
         MailDA.UpdateMailMessage(message);
     }
 }
Example #5
0
        public static bool SendMail(string payTypeDesc, int SOSysNo, decimal so, decimal ar, decimal invoice)
        {
            string subject  = Settings.MailSubject + "-" + SOSysNo.ToString();
            string mailBody = GetMailBody(payTypeDesc, SOSysNo, so, ar, invoice);
            string address  = Settings.EmailAddress;

            return(MailDA.SendEmail(SOSysNo, address, subject, mailBody));
        }
Example #6
0
        /// <summary>
        /// 记录MailMessage的信息到DB
        /// </summary>
        /// <param name="message"></param>
        /// <param name="setting"></param>
        /// <returns></returns>
        public static string LogMail(MailMessage message, MailPageSetting setting)
        {
            if (message == null)
            {
                throw new ArgumentNullException("MailMessage");
            }

            using (var scope = new TransactionScope())
            {
                if (!string.IsNullOrWhiteSpace(message.TemplateID))
                {
                    message.IsSentByTemplate = true;
                }
                else
                {
                    message.IsSentByTemplate = false;
                }

                //记录MailMessage的信息
                message.MessageID = MailDA.LogMailMessage(message);

                //记录BusinessNumber的信息
                if (message.BusinessNumberList != null && message.BusinessNumberList.Count > 0)
                {
                    MailDA.LogBusinessNumber(message.MessageID, message.BusinessNumberList);
                }
                //记录MailTemplateVariable的信息
                if (!string.IsNullOrWhiteSpace(message.TemplateID) && message.MailTemplateVariables != null)
                {
                    MailDA.LogTemplateVariable(message.MessageID, message.MailTemplateVariables);
                }

                //记录PageSetting的信息
                if (setting != null)
                {
                    MailDA.LogPageSetting(message.MessageID, setting);
                }

                scope.Complete();
            }
            return(message.MessageID);
        }
Example #7
0
 public bool?GetMailStatus(string messageID)
 {
     if (!string.IsNullOrWhiteSpace(messageID))
     {
         var status = MailDA.GetMailStatus(messageID);
         if (status)
         {
             return(status);
         }
         else
         {
             var key = string.Format(Sessionkey_IsCloseMailPage, messageID);
             if (HttpContext.Current.Session[key] != null && (bool)HttpContext.Current.Session[key])
             {
                 return(false);
             }
         }
     }
     return(null);
 }
Example #8
0
 public static void SendMail(string subject, string mailBody, int status)
 {
     MailDA.SendEmail(Settings.EmailAddress, subject, mailBody, status);
 }
Example #9
0
        private static void SendEmailForData(ZeroConfirmSOIncomeJobResp response)
        {
            if (response == null)
            {
                return;
            }

            DateTime nowTime        = DateTime.Now;
            string   emailModelPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.EmailModel);
            string   emailBody      = ReadFile(emailModelPath);

            emailBody = emailBody.Replace("#DateTime#", nowTime.ToString("yyyy-MM-dd HH:mm:ss"));

            List <ConfirmEntity> emailList = new List <ConfirmEntity>();

            response.Result.ForEach(x =>
            {
                var s           = AutoConfirm.GetEmailData(Convert.ToInt32(x.SysNo));
                var confirmInfo = "确认成功";
                if (x.ErrorDescription != null)
                {
                    confirmInfo = x.ErrorDescription;
                }

                string confirmedID = Settings.UserLoginName;

                emailList.Add(new ConfirmEntity {
                    SoSysNo        = s.SoSysNo,
                    PayTerms       = s.PayTerms,
                    OrderAmt       = s.OrderAmt,
                    IncomeAmt      = s.IncomeAmt,
                    PrepayAmt      = s.PrepayAmt,
                    PointPayAmt    = s.PointPayAmt,
                    GiftCardPayAmt = s.GiftCardPayAmt,
                    ConfirmedDate  = s.ConfirmedDate,
                    ConfirmedInfo  = confirmInfo,
                    CofirmedID     = confirmedID
                });
            });

            MailInfo mail = new MailInfo();

            string fileName = "ZeroAutoConfirm" + nowTime.ToString(Settings.ShortDateFormat) + ".xls";

            string filePath = new ExcelSend().WriteToFile(emailList, fileName, nowTime);

            mail.FromName   = Settings.EmailFrom;
            mail.ToName     = Settings.EmailAddress;
            mail.Subject    = string.Format(Settings.EmailSubject, nowTime.ToString(Settings.ShortDateFormat));
            mail.Body       = emailBody;
            mail.IsHtmlType = false;

            mail.Attachments = new List <string>();
            mail.Attachments.Add(filePath);
            mail.IsAsync    = false;
            mail.IsInternal = true;

            try
            {
                MailHelper.SendEmail(mail);
                MailDA.SendEmail(mail.ToName, mail.Subject, mail.Body, 1);
                OnShowInfo("邮件发送成功");
            }
            catch
            {
                MailDA.SendEmail(mail.ToName, mail.Subject, mail.Body, -1);
                OnShowInfo("邮件发送失败");
            }
        }
Example #10
0
 public static void SendMail(string mailto, string subject, string mailBody, int status)
 {
     MailDA.SendEmail(mailto, subject, mailBody, status);
 }
Example #11
0
        private static void CreateData(XmlDocument xmlResult, string AttachInfo2)
        {
            var zfbDA      = new ZFBDA();
            var entityList = new List <ZFBDataEntity>();
            var now        = DateTime.Now;

            XmlNodeList nodeList = xmlResult.GetElementsByTagName("csv_data");

            if (nodeList.Count == 0)
            {
                throw new Exception("获取数据失败");
            }
            string strResult = nodeList[0].InnerXml;

            XmlNodeList nodeList01 = xmlResult.GetElementsByTagName("is_success");
            string      flag       = nodeList01[0].InnerXml;

            XmlNodeList nodeList02 = xmlResult.GetElementsByTagName("count");
            int         countList  = int.Parse(nodeList02[0].InnerXml);


            if (flag == "F")
            {
                throw new Exception("获取失败,is_success标识为F");
            }
            if (countList <= 0)
            {
                throw new Exception("当天没有交易记录");
            }

            //去掉左右冗余符号
            strResult = strResult.Replace("&lt;![CDATA[", "").Replace("]]&gt;", "").Replace("\n", "").Trim();
            string[]  resultArray = strResult.Split(',');
            const int coulmnCount = 14;
            int       rowCount    = resultArray.Count() / coulmnCount - 1;

            DataTable  table = new DataTable();
            DataColumn column;
            DataRow    row;

            //加列头
            for (int i = 0; i < coulmnCount; i++)
            {
                column            = new DataColumn();
                column.DataType   = System.Type.GetType("System.String");
                column.ColumnName = resultArray[i];
                table.Columns.Add(column);
            }
            //加行
            int index = coulmnCount;

            for (int j = 0; j < rowCount; j++)
            {
                row = table.NewRow();
                for (int i = 0; i < coulmnCount; i++)
                {
                    row[i] = resultArray[index++];
                }
                table.Rows.Add(row);
            }

            foreach (DataRow rowData in table.Rows)
            {
                try
                {
                    var soSysNo          = Convert.ToInt32(rowData[0]);
                    var getPayTypeResult = zfbDA.GetPayType(soSysNo);
                    if (getPayTypeResult == null || getPayTypeResult.Count == 0)
                    {
                        throw new Exception("SO_Master中查找不到该订单信息");
                    }
                    PayTypeEntity paytypeEntity = getPayTypeResult[0];

                    entityList.Add(new ZFBDataEntity
                    {
                        SoSysNo       = soSysNo,
                        PayTermsNo    = paytypeEntity.PayTermsNo,
                        PayTerms      = paytypeEntity.PayTerms,
                        PayedDate     = Convert.ToDateTime(rowData[2]),
                        PayedAmt      = Convert.ToDecimal(rowData[8]),
                        SerialNumber  = rowData[3].ToString(),
                        OutOrderNo    = rowData[4].ToString(),
                        PayedUserTag  = rowData[5].ToString(),
                        PayedUserName = rowData[6].ToString(),
                        PayedUserNo   = rowData[7].ToString(),
                        PartnerName   = "支付宝",
                        TradeType     = rowData[12].ToString(),
                        AttachInfo    = rowData[11].ToString(),
                        AttachInfo2   = AttachInfo2,
                        InUser        = "******",
                        InDate        = now
                    });
                }
                catch (Exception ex)
                {
                    string[] strArray = rowData.ItemArray.Select(x =>
                    {
                        return(x == null ? string.Empty : x.ToString());
                    }).ToArray <string>();
                    string details = string.Format("异常订单信息 SoSysNo:{0},InDate:{1},Error:{2},ErrorInfoSource:{3}",
                                                   rowData[0].ToString(),
                                                   rowData[2].ToString(),
                                                   ex.Message,
                                                   string.Join(",", strArray));
                    OnShowInfo(details);
                    SendMail("支付宝对账异常", details);

                    if (rowData[0].ToString().Length >= 9)
                    {
                        var longInfo = string.Format("支付宝过长订单号信息提醒 SoSysNo:{0},InDate:{1},ErrorInfoSource:{2}",
                                                     rowData[0].ToString(),
                                                     rowData[2].ToString(),
                                                     string.Join(",", strArray));
                        MailDA.SendEmail(Settings.LongOrderSysNoAlert, "支付宝过长订单号信息提醒", longInfo);
                    }
                    else if (ex.Message.Contains("SO_Master中查找不到该订单信息"))
                    {
                        var longInfo = string.Format("无法确认支付宝订单提醒 SoSysNo:{0},InDate:{1},ErrorInfoSource:{2}",
                                                     rowData[0].ToString(),
                                                     rowData[2].ToString(),
                                                     string.Join(",", strArray));
                        MailDA.SendEmail(Settings.LongOrderSysNoAlert, "无法确认支付宝订单提醒", longInfo);
                    }
                }
            }

            if (lastInfo != null && lastInfo.Count > 0)
            {
                entityList = entityList.Except(lastInfo, new ZFBEntityComparer()).ToList();
            }

            if (entityList == null || entityList.Count == 0)
            {
                throw new Exception("不存在可导入记录");
            }
            OnShowInfo("开始导入数据");
            try
            {
                //每一百条数据导入一次
                var entityMiddle = new List <ZFBDataEntity>();
                for (int i = 0; i < entityList.Count; i++)
                {
                    entityMiddle.Add(entityList[i]);
                    if ((i != 0 && (i + 1) % 100 == 0) || (i + 1) == entityList.Count)
                    {
                        zfbDA.CreateData(entityMiddle);
                        OnShowInfo(string.Format("导入了{0}条记录", (i + 1).ToString()));
                        entityMiddle.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                OnShowInfo(string.Format("导入失败:{0}", ex.Message));
            }
            OnShowInfo("导入完毕");
        }
Example #12
0
 public static void SendEmail(string mailSubject, string mailBody)
 {
     MailDA.SendEmail(Settings.MailAddress, mailSubject, mailBody);
 }
Example #13
0
        /// <summary>
        /// 根据MessageID获取Mail的相关信息和PageSetting的信息
        /// </summary>
        /// <param name="messageID"></param>
        /// <returns></returns>
        public static MailPageMessage GetMailMessage(string messageID)
        {
            MailPageMessage result  = new MailPageMessage();
            MailMessage     message = null;

            Parallel.Invoke(
                () =>
            {
                message = MailDA.GetMailMessage(messageID);
                if (message != null)
                {
                    message.BusinessNumberList = MailDA.GetBusinessNumber(messageID);
                }
            },
                () =>
            {
                result.MailPageSetting = MailDA.GetPageSetting(messageID);
            });

            //如果使用模板方式发送邮件,则需要调用London II的服务获取模板内容
            if (message != null && !string.IsNullOrWhiteSpace(message.TemplateID))
            {
                var templateIDs = message.TemplateID.Split(',');
                var collection  = new List <MailMessage>();

                //并行获取所有TemplateID的内容
                Parallel.ForEach(templateIDs, (templateID) =>
                {
                    var msg = SerializationUtility.XmlDeserialize <MailMessage>(SerializationUtility.XmlSerialize(message));

                    var variable = MailDA.GetTemplateVariable(messageID);
                    msg.MailTemplateVariables = variable;
                    msg.TemplateID            = templateID;

                    var query          = new GetEmailContentMessageV10();
                    query.SystemID     = msg.SystemID;
                    query.TemplateID   = templateID;
                    query.CompanyCode  = msg.CompanyCode;
                    query.CountryCode  = msg.CountryCode;
                    query.LanguageCode = msg.LanguageCode;

                    var content = MailProvider.London.GetEmailContentByTemplate(query, variable.ToKeyValue());

                    if (content != null)
                    {
                        msg.From    = content.FromName;
                        msg.Subject = content.Subject;
                        msg.Body    = content.Body;
                    }

                    lock (s_syncObj)
                    {
                        collection.Add(msg);
                    }
                });

                result.MailCollection = collection;

                if (collection.Count > 0)
                {
                    result.MailMessage = collection[0];
                }
            }
            else
            {
                result.MailMessage = message;
            }

            return(result);
        }