/// <summary> /// 获取Excel附件字节阵列 /// </summary> /// <param name="entities"></param> /// <returns></returns> private static byte[] GetExcelContent(List <ARAmtOfVIPCustomerEntity> entities) { ExcelSend excelSend = new ExcelSend(); byte[] result = excelSend.Getbytes(entities); return(result); }
/// <summary> /// 发送邮件 /// </summary> /// <param name="dataTable"></param> private static void SendMail(List <ARAmtOfVIPCustomerEntity> entities) { MailInfo mail = new MailInfo(); string fileName = string.Format("ARAmtOfVIPCustomer_{0}.xls", DateTime.Now.ToString(JobConfig.DateFormat)); //byte[] excelContent = GetExcelContent(entities); //MailAttachment mailAttachment = new MailAttachment(fileName, excelContent, MediaType.Other); string filePath = new ExcelSend().WriteToFile(entities, fileName); mail.FromName = JobConfig.MailSendAddress; mail.ToName = JobConfig.MailRecvAddress; mail.Subject = string.Format(JobConfig.MailSubject, DateTime.Now.ToString(JobConfig.DateFormat)); mail.Body = JobConfig.MailBody; mail.IsHtmlType = false; mail.Attachments = new List <string>(); mail.Attachments.Add(filePath); mail.IsAsync = false; mail.IsInternal = true; MailHelper.SendEmail(mail); }
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("邮件发送失败"); } }