private static void CheckTestMailBody(ref EmailNotice eNotice) { if (WebConfigurationManager.AppSettings["eMailTry"] == "Test") { eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:TestEmailTo}}", "Email To: " + eNotice.EmailTo); eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:TestEmailCC}}", "Email CC: " + eNotice.EmailCC); eNotice.EmailTo = eNotice.EmailFrom; eNotice.EmailCC = "*****@*****.**"; eNotice.EmailBcc = ""; } else { eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:TestEmailTo}}", ""); eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:TestEmailCC}}", ""); } string applicationSite = WebConfigurationManager.AppSettings["ApplicationSite"]; if (eNotice.EmailFormat == "HTML") { string appUrl = " <a href=' " + applicationSite + "' target='_blank'> Teacher Performance Appraisal </a>"; eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:WebSite}}", appUrl); eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:OneLine}}", "<br />"); } else { eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:WebSite}}", applicationSite); eNotice.EmailBody = eNotice.EmailBody.Replace("{{PlaceHolder:OneLine}}", ""); } }
public static string SendMailWithiCalendar(EmailNotice eNotice, System.Net.Mail.Attachment iCalendar) { string result = "Failed"; try { System.Net.Mail.SmtpClient myMail = new System.Net.Mail.SmtpClient(); myMail.Host = WebConfigurationManager.AppSettings["SMTPServer"]; var Mailmsg = new System.Net.Mail.MailMessage(); Mailmsg = GetMailMsg(eNotice); Mailmsg.Attachments.Add(iCalendar); try { myMail.Send(Mailmsg); } catch (Exception ex) { string ms = ex.Message; } Mailmsg.Dispose(); result = "Successfully"; } catch (Exception ex) { string ms = ex.Message; result = "Failed"; } return(result); }
protected void tester_Click(object sender, EventArgs e) { try { EmailNotice notice = new EmailNotice(); notice.Scheduled = DateTime.Now.AddDays(30); notice.NoticeType = NoticeType.Checkout; notice.NoticeAction = Global.CheckoutAction; var assets = new List <Asset>() { Global.Library.Assets[0], Global.Library.Assets[1], Global.Library.Assets[2], Global.Library.Assets[3], Global.Library.Assets[4] }; foreach (var ass in assets) { notice.Assets.Add(ass.AssetNumber); } notice.NoticeControlNumber = assets[0].OrderNumber; notice.Body = Global.Library.Settings.CheckOutMessage; notice.Subject = "Asset Return Reminder"; var engineer = (from d in Global.Library.Settings.ServiceEngineers where d.Name == assets[0].ServiceEngineer select d).FirstOrDefault(); var statics = (from d in Global.Library.Settings.StaticEmails select d).ToList(); notice.Emails.Add(engineer); notice.Emails.AddRange(statics); notice.EmailAddress = engineer; Global.NoticeSystem.Add(notice); var a = Global.NoticeSystem.SerializeToXmlString(Global.NoticeSystem); } catch { } }
/// <summary> /// 添加一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(EmailNotice model, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into EmailNotice("); strSql.Append(" EmailNoticeAuthor,AuthorID,MainID,MainType,MD5Key,MD5Sign,CreateTime )"); strSql.Append(" values ("); strSql.Append("@EmailNoticeAuthor,@AuthorID,@MainID,@MainType,@MD5Key,@MD5Sign,@CreateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@EmailNoticeAuthor", model.EmailNoticeAuthor), new SqlParameter("@AuthorID", model.AuthorID), new SqlParameter("@MainID", model.MainID), new SqlParameter("@MainType", model.MainType), new SqlParameter("@MD5Key", model.MD5Key), new SqlParameter("@MD5Sign", model.MD5Sign), new SqlParameter("@CreateTime", model.CreateTime), }; object obj; if (tran == null) { obj = SqlHelper.GetSingle(strSql.ToString(), CommandType.Text, parameters); } else { obj = SqlHelper.GetSingle(tran, CommandType.Text, strSql.ToString(), parameters); } return(obj == null ? 0 : Convert.ToInt32(obj)); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(EmailNotice model, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("update EmailNotice set "); strSql.Append("EmailNoticeAuthor=@EmailNoticeAuthor,AuthorID=@AuthorID,MainID=@MainID,MainType=@MainType,MD5Key=@MD5Key,MD5Sign=@MD5Sign,CreateTime=@CreateTime"); strSql.Append(" where EmailNoticeId=@EmailNoticeId"); SqlParameter[] parameters = { new SqlParameter("@EmailNoticeAuthor", model.EmailNoticeAuthor), new SqlParameter("@AuthorID", model.AuthorID), new SqlParameter("@MainID", model.MainID), new SqlParameter("@MainType", model.MainType), new SqlParameter("@MD5Key", model.MD5Key), new SqlParameter("@MD5Sign", model.MD5Sign), new SqlParameter("@CreateTime", model.CreateTime), new SqlParameter("@EmailNoticeId", model.EmailNoticeId) }; if (tran == null) { return(SqlHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters) > 0); } else { return(SqlHelper.ExecuteSql(tran, CommandType.Text, strSql.ToString(), parameters) > 0); } }
/// <summary> /// 修改 (可能有其他业务逻辑检查) /// </summary> /// <param name="model"></param> /// <returns></returns> public ResultInfo Update(EmailNotice model, SqlTransaction tran = null) { ResultInfo ri = new ResultInfo(); if (Edit(model, tran)) { ri.Ok = true; ri.Msg = "修改成功"; } return(ri); }
private static System.Net.Mail.MailMessage GetMailMsg(EmailNotice eNotice) { try { CheckTestMailBody(ref eNotice); var Mailmsg = new System.Net.Mail.MailMessage(); Mailmsg.To.Clear(); LoopAddress("mailTo", eNotice.EmailTo, ref Mailmsg); LoopAddress("mailCC", eNotice.EmailCC, ref Mailmsg); LoopAddress("mailBcc", eNotice.EmailBcc, ref Mailmsg); LoopAddress("mailFrom", eNotice.EmailFrom, ref Mailmsg); Mailmsg.Subject = eNotice.EmailSubject; Mailmsg.Priority = MailPriority.High; if (eNotice.EmailFrom == "HTML") { Mailmsg.IsBodyHtml = true; } Mailmsg.Body = eNotice.EmailBody; if (!string.IsNullOrEmpty(eNotice.Attachment1)) { AddAttachments(eNotice.Attachment1, ref Mailmsg); } if (!string.IsNullOrEmpty(eNotice.Attachment2)) { AddAttachments(eNotice.Attachment2, ref Mailmsg); } if (!string.IsNullOrEmpty(eNotice.Attachment3)) { AddAttachments(eNotice.Attachment3, ref Mailmsg); } if (eNotice.FileMemory != null) { MemoryStream attaStream = new MemoryStream(eNotice.FileMemory); attaStream.Position = 0; System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType(eNotice.FileType); // "application/pdf"); System.Net.Mail.Attachment attaFile = new Attachment(attaStream, contentType); attaFile.ContentDisposition.FileName = eNotice.FileName; Mailmsg.Attachments.Add(attaFile); } return(Mailmsg); } catch (Exception ex) { string ms = ex.Message; return(null); } }
public static string SendMail(string eMailTo, string eMailCC, string eMailBcc, string eMailForm, string eMailSubject, string eMailBody, string eMailFormat) { var eNotice = new EmailNotice { EmailTo = eMailTo, EmailCC = eMailCC, EmailFrom = eMailForm, EmailBcc = eMailBcc, EmailSubject = eMailSubject, EmailBody = eMailBody, EmailFormat = eMailFormat }; return(SendMail(eNotice)); }
public static string SendMail(string eMailTo, string eMailCC, string eMailBcc, string eMailForm, string eMailSubject, string eMailBody, string eMailFormat, System.Net.Mail.Attachment iCal) { var eNotice = new EmailNotice { EmailTo = eMailTo, EmailCC = eMailCC, EmailFrom = eMailForm, EmailBcc = eMailBcc, EmailSubject = eMailSubject, EmailBody = eMailBody, EmailFormat = eMailFormat }; return(SendMail(eNotice)); }
public static EmailNotice GetEmailNoticeParamemeter(string emailTypemail, string emailTo, string emailCC, string emailBcc, string emailFrom, string emailFormat, string emailSubject, string emailBody, string att1, string att2, string att3) { EmailNotice parameters = new EmailNotice() { EmailType = emailTypemail, EmailTo = emailTo, EmailCC = emailCC, EmailBcc = emailBcc, EmailFrom = emailFrom, EmailFormat = emailFormat, EmailSubject = emailSubject, EmailBody = emailBody, Attachment1 = att1, Attachment2 = att2, Attachment3 = att3, }; return(parameters); }
/// <summary> /// 保存 (可能有其他业务逻辑检查) /// </summary> /// <param name="model">实体</param> /// <returns></returns> public ResultInfo Create(EmailNotice model, SqlTransaction tran = null) { ResultInfo ri = new ResultInfo(); if (model == null) { return(ri); } int result = Add(model, tran); if (result > 0) { ri.Ok = true; ri.Msg = "添加成功"; } return(ri); }
public void NotifyCheckoutEmail(List <Asset> assets) { if (Global.Library.Settings.TESTMODE == false) { try { EmailHelper.SendNoticeAsync(assets, Global.Library.Settings.CheckOutMessage); } catch { ShowError("Problem Sending Emails"); } try { EmailNotice n = new EmailNotice(); n.Scheduled = DateTime.Now.AddDays(30); n.NoticeType = NoticeType.Chekout; n.NoticeAction = Global.CheckoutAction; n.Assets = assets; n.NoticeControlNumber = assets.FirstOrDefault().OrderNumber; n.Name = assets[0].OrderNumber; Global.NoticeSystem.Add(n); var task = Save.NotificationSystemAsync(); } catch { ShowError("Problem Adding Timed Notice"); } } }
public void TD(long actionid, string actionid2, string actionid3 = "-1") { string msg = string.Empty; try { int mainType = Convert.ToInt32(actionid3); long mainID = actionid; long authorID = 0; string title = string.Empty; if (mainType != -1) { bool ok = false; if (mainType == 1) { Question qmodel = QuestionBLL.Instance.GetModel(actionid); if (qmodel == null) { msg = "邮件校验不成功,退订不成功"; } else { authorID = Convert.ToInt64(qmodel.UserID); title = qmodel.Title; ok = true; } } else if (mainType == 5) { ZhaoPin zmodel = ZhaoPinBLL.Instance.GetModel(mainID); if (zmodel == null) { msg = "邮件校验不成功,退订不成功"; } else { authorID = Convert.ToInt64(zmodel.Publisher); title = zmodel.Gangwei; ok = true; } } if (ok) { EmailNotice emodel = EmailNoticeBLL.Instance.GetModelByAuthor(authorID, mainType, actionid); if (emodel == null) { msg = "邮件退订状态不正常"; } else { //比较签名 if (emodel.MD5Sign == actionid2) { if (emodel.EmailNoticeAuthor == 0) { msg = "您已退订"; } else { emodel.EmailNoticeAuthor = 0; emodel.CreateTime = DateTime.Now; if (EmailNoticeBLL.Instance.Update(emodel).Ok) { msg = "退订成功"; } } } else { msg = "邮件校验不成功,退订不成功"; } } } } } catch { } Response.Write(msg); }
protected void FinalizeBtn_Click(object sender, EventArgs e) { if (ShippingMethodDropDownList.Text == "") { ShowError("Please Select A Shipping Option"); return; } var checkoutdata = Session["CheckOutData"] as CheckOutData; checkoutdata = UpdateCheckOutData(checkoutdata); if (checkoutdata.CheckOutItems == null) { return; } if (checkoutdata.CheckOutItems.Count > 0) { if (checkoutdata.Package.Weight == null) { ShowError("No Package Weight."); return; } if (checkoutdata.From.AddressLine[0] != "" && checkoutdata.To.AddressLine[0] != "" && checkoutdata.Shipper.AddressLine[0] != "" && checkoutdata.Package.Weight != "") { var ud = Session["SessionUserData"] as Data.UserData; ud.Log.Add(new Data.LogEntry("Order#" + checkoutdata.CheckOutItems.FirstOrDefault().OrderNumber, Session["CombinedPdf"] as string)); Finalized = true; PackingSlipViewBtn.Enabled = true; UpdateCost(); UpdateArrival(); CreatePackingSlip(); UpdateUpsLabel(); Shake(ReportLink); try { EmailNotice notice = new EmailNotice(); notice.Scheduled = DateTime.Now.AddDays(30); notice.NoticeType = NoticeType.Checkout; notice.NoticeAction = Global.CheckoutAction; foreach (var asset in checkoutdata.CheckOutItems) { notice.Assets.Add(asset.AssetNumber); } notice.NoticeControlNumber = checkoutdata.CheckOutItems[0].OrderNumber; notice.Body = Global.Library.Settings.CheckOutMessage; notice.Subject = "Asset Return Reminder"; var engineer = (from d in Global.Library.Settings.ServiceEngineers where d.Name == Session["Engineer"] as string select d).FirstOrDefault(); var statics = (from d in Global.Library.Settings.StaticEmails select d).ToList(); if (engineer == null) { engineer = new EmailAddress(); } notice.Emails.Add(engineer); notice.Emails.AddRange(statics); notice.EmailAddress = engineer; Global.NoticeSystem.Add(notice); Save.NotificationSystem(); } catch { ShowError("Problem Adding Timed Notice"); } SaveToUserPersistantLog(); FinalizeAssets(Session["Checkout"] as List <Asset>); Session["Checkout"] = new List <Asset>(); but_OK.Enabled = false; FinalizeHolder.Visible = false; CheckoutView.ActiveViewIndex = 1; // goto report } else { ShowError("Please fill in form completely."); } } else { ShowError("There are no items in Check Out"); } }
static async Task DoDifferentAction(string ip, string lastIp) { Log.Info($"检测到外网IP已变更,当前IP:{ip},历史IP:{lastIp}"); if (ConfigManager.Now.AppSettings.IsEnableEmailNotice) { if (string.IsNullOrEmpty(ConfigManager.Now.AppSettings.EmailApiConfig.Host) || string.IsNullOrEmpty(ConfigManager.Now.AppSettings.EmailApiConfig.Account) || string.IsNullOrEmpty(ConfigManager.Now.AppSettings.EmailApiConfig.Passwd)) { Log.Info($"邮件配置不正确,已跳过。"); } else { try { EmailNotice email = new EmailNotice(); (bool, string) result = email.Send(ip, lastIp); if (result.Item1) { Log.Info($"IP变更邮件提醒已发送,接收邮箱:{ConfigManager.Now.AppSettings.EmailApiConfig.ReceiveAddress}。"); } else { Log.Info($"IP变更邮件提醒发送失败,错误:{result.Item2}"); } } catch (Exception ex) { Log.Error(ex.Message, ex); } } } if (ConfigManager.Now.AppSettings.IsEnableMessageNotice) { if (string.IsNullOrEmpty(ConfigManager.Now.AppSettings.MessageApiConfig.AppKey) || string.IsNullOrEmpty(ConfigManager.Now.AppSettings.MessageApiConfig.MessageTemplate) || string.IsNullOrEmpty(ConfigManager.Now.AppSettings.MessageApiConfig.URL) || string.IsNullOrEmpty(ConfigManager.Now.AppSettings.MessageApiConfig.Mobile)) { Log.Info($"短信配置不正确,已跳过。"); } else { try { MessageNotice message = new MessageNotice(); (bool, string) result = await message.Send(ip, lastIp); if (result.Item1) { Log.Info($"IP变更短信提醒已发送,接收电话:{ConfigManager.Now.AppSettings.MessageApiConfig.Mobile}。"); } else { Log.Info($"IP变更短信提醒发送失败,错误:{result.Item2}"); } } catch (Exception ex) { Log.Error(ex.Message, ex); } } } if (ConfigManager.Now.DdnsConfig.IsEnableDdns) { if (ConfigManager.Now.DdnsConfig.Domains == null || ConfigManager.Now.DdnsConfig.Domains.Count == 0) { Log.Info($"未发现要设置DDNS的域名配置,DDNS已跳过。"); } if (ConfigManager.Now.DdnsConfig.DdnsServiceProviders == null || ConfigManager.Now.DdnsConfig.DdnsServiceProviders.Count == 0) { Log.Info($"未发现DDNS服务提供配置,DDNS已跳过。"); } else { try { new DomainDdnsService().UpdateDomainInfo(ip); } catch (Exception ex) { Log.Error(ex.Message, ex); } } } else { Log.Info($"DDNS已关闭,跳过域名DDNS。"); } }
/// <summary> /// 修改一条记录 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public bool Edit(EmailNotice model, SqlTransaction tran = null) { return(dal.Update(model, tran)); }
/// <summary> /// 添加一条记录,没有任何逻辑 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public int Add(EmailNotice model, SqlTransaction tran = null) { return(dal.Add(model, tran)); }
protected void UploadAssetCertificateBtn_Click(object sender, EventArgs e) { try { int test = Convert.ToInt32(CalPeriod.Value); } catch { return; } if (CalCompany.Value == "") { return; } var asset = Session["Asset"] as Asset; var ext = Path.GetExtension(CertUpload.FileName); if (ext == "") { ext = ".pdf"; } var file = System.Guid.NewGuid().ToString(); var dest = Server.MapPath("/Account/Certs/" + asset.AssetNumber + file + ext); using (FileStream fs = new FileStream(dest, FileMode.Create)) { CertUpload.FileContent.CopyTo(fs); } try { CalibrationData cd = new CalibrationData(); cd.AssetNumber = asset.AssetNumber; cd.CalibrationCompany = CalCompany.Value.Sanitize(); try { cd.SchedulePeriod = Convert.ToInt32(CalPeriod.Value); } catch { } cd.ImagePath = "/Account/Certs/" + asset.AssetNumber + file + ext; asset.CalibrationHistory.Calibrations.Add(cd); Save.Asset(asset); //ADD NOTIFICATION try { EmailNotice notice = new EmailNotice(); notice.Scheduled = DateTime.Now.AddDays(30); notice.NoticeType = NoticeType.Calibration; notice.NoticeAction = Global.CalibrationAction; notice.NoticeControlNumber = asset.AssetNumber; notice.Body = Global.Library.Settings.CalibrationMessage; var statics = (from d in Global.Library.Settings.StaticEmails select d).ToList(); EmailAddress person = new EmailAddress(); if (statics.Count != 0) { person = statics.FirstOrDefault(); } notice.Emails.AddRange(statics); notice.EmailAddress = person; notice.Scheduled = DateTime.Now.AddMonths(Convert.ToInt32(CalPeriod.Value)).AddDays(-14); Global.NoticeSystem.Add(notice); Save.NotificationSystem(); } catch { } //register startup script to hide cal uploader BindCalibration(); Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "HideCalUploader()", true); } catch { } }