public void Handle(OnSessionRegisteredEvent ars) { var title = ars.Subject.Replace("##TITLE##", ars.Session.Title); var body = ars.Body.Replace("##TITLE##", ars.Session.Title).Replace("##TOKEN##", ars.Session.Token); EmailCommon.Send(body, title, ars.Session); }
public void Handler(OnForgotUserEvent ars) { var body = ars.Body.Replace("#name#", ars.User.FullName).Replace("#password#", ars.NewPassword); var subject = ars.Subject; EmailCommon.Send(body, subject, ars.User); }
public void Handler(OnWelcomeUserEvent ars) { var body = ars.Body.Replace("#name#", ars.User.FullName).Replace("#email#", ars.User.Email) .Replace("#password#", ars.NewPassword); var subject = ars.Subject.Replace("#name#", ars.User.FirstName); EmailCommon.Send(body, subject, ars.User); }
public ActionResult SendEventEmail(long id) { var events = eventService.GetById(id); if (!events.UsersFollow.Any()) { return(null); } var to = events.UsersFollow.Where(x => string.IsNullOrEmpty(x.User.Email)).Select(x => x.User.Email).ToArray(); if (!to.Any()) { return(Json(new { Message = @"Gửi email thất bại! Lỗi: không tồn tại email người nhận ", Success = false, }, JsonRequestBehavior.AllowGet)); } var dept = usersServices.GetAll( x => x.DeptId == CurrenUser.DeptId && x.RoleName == UsersModel.Positions.Manager.ToString()); var ccEmail = string.Empty; ccEmail = dept.Where(u => string.IsNullOrEmpty(u.Email)).Aggregate(ccEmail, (current, u) => current + (u.Email + ",")); var admin = usersServices.FindEntity(x => x.UserName.ToLower() == "admin"); var user = !string.IsNullOrEmpty(CurrenUser.Email) ? CurrenUser : admin; var model = new EmailModel { EmailTo = string.Join(",", to), User = user, EmailCc = ccEmail + CurrenUser.Email, Message = string.Format("Bạn được yêu cầu cùng tham gia sự kiện {0} vào ngày {1:dd/MM/yyyy}", events.Subject, events.DateBegin), Subject = events.Subject }; var email = new EmailCommon { EmailModel = model }; string errorMessages; if (email.SendEmail(out errorMessages, true)) { return(Json(new { Message = @"Gửi email thành công", Success = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { Message = @"Gửi email thất bại! Lỗi: " + errorMessages, Success = false, }, JsonRequestBehavior.AllowGet)); }
static void Main(string[] args) { string from = "*****@*****.**"; //发送者邮箱 string fromer = "裕睿软件@Yuruisoft.com"; //发送人 string to = "*****@*****.**"; //接受者邮箱 string toer = "小王"; //收件人 string Subject = "这只是个测试!"; //主题 string file = @"C:\Users\Administrator\Desktop\02_asp.net_mvc_框架EasyUI快速开发框架通用权限管理.rar"; //附件 string Body = "这只是个测试!"; //内容 string SMTPHost = "smtp.163.com"; string SMTPuser = "******"; string SMTPpass = "******"; string errMessage = null; if (!EmailCommon.sendmail(from, fromer, to, toer, Subject, Body, file, SMTPHost, SMTPuser, SMTPpass, out errMessage)) { Console.Write("{0}", errMessage); } else { Console.Write("发送成功!"); } Console.ReadKey(); }
public ActionResult FindPwd() { string txtName = Request["txtName"]; string txtMail = Request["txtMail"]; if (txtName == null || txtMail == null) { return(Content("no:")); } var userInfo_EMail = userInfoService.LoadEntities(u => u.UName == txtName).Select(c => c.UEmail).FirstOrDefault(); if (userInfo_EMail == txtMail) { string Vcode = Guid.NewGuid().ToString("N"); SingleFindPSWcache.GetFindPSWcache().findPSWcache[txtName] = Vcode; //message.Body = mail.Body;//邮件内容 //message.BodyEncoding = mail.BodyEncoding;//邮件采用的编码 //message.Subject = mail.Subject;//邮件标题 //message.SubjectEncoding = mail.SubjectEncoding;//主题内容使用编码 //message.IsBodyHtml = mail.IsBodyHtml;//邮件格式 System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage(); //两个类,别混了,要引入System.Net这个Assembly mailMsg.Subject = "Yuruisoft综合管理系统-密码找回服务"; //发送邮件的标题 mailMsg.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312"); mailMsg.IsBodyHtml = true; //采用HTML格式 StringBuilder sb = new StringBuilder(); #region HTML代码A段 sb.Append(@"<style type='text/css'>.ReadMsgBody{width:100%;background-color:#fff}.ExternalClass{width:100%;background-color:#fff}.ExternalClass,.ExternalClass p,.ExternalClass span,.ExternalClass font,.ExternalClass td,.ExternalClass div{line-height:100%}html{width:100%}body{-webkit-text-size-adjust:none;-ms-text-size-adjust:none;margin:0;padding:0}table{border-spacing:0;border-collapse:collapse;table-layout:fixed;margin:0 auto}table table table{table-layout:auto}img{display:block!important}table td{border-collapse:collapse}.yshortcuts a{border-bottom:none!important}a{color:#91c444;text-decoration:none}.textbutton a{font-family:'open sans',arial,sans-serif!important;color:#fff!important}.text-link a{color:#3b3b3b!important}@media only screen and (max-width:640px){body{width:auto!important}table[class='table600']{width:450px!important}table[class='table-inner']{width:90%!important}table[class='table3-3']{width:100%!important;text-align:center!important}}@media only screen and (max-width:479px){body{width:auto!important}table[class='table600']{width:290px!important}table[class='table-inner']{width:82%!important}table[class='table3-3']{width:100%!important;text-align:center!important}}</style><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#494c50'><tr><td align='center' background='http://www.yurusoft.net/Content/Yuruisoft.RS.Images/bg.jpg' style='background-size:cover; background-position:top;'><table class='table600' width='600' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td height='60'></td></tr><tr><td align='center'><table style='border-top:3px solid #91c444; border-radius:4px;box-shadow: 0px 3px 0px #bdc3c7;' bgcolor='#FFFFFF' width='100%' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td align='center'><table width='550' align='center' class='table-inner' border='0' cellspacing='0' cellpadding='0'><tr><td height='15'></td></tr><tr><td><!-- logo --><table class='table3-3' width='50' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td align='center' style='line-height:0px;'><img style='display:block; line-height:0px; font-size:0px; border:0px;' src='http://www.yurusoft.net/Content/Images/login/logo.png' width='50' height='26' alt='logo' /></td></tr></table><!-- end logo --><!--Space--><table width='1' height='15' border='0' cellpadding='0' cellspacing='0' align='left'><tr><td height='15' style='font-size: 0;line-height: 0;border-collapse: collapse;'><p style='padding-left: 24px;'> </p></td></tr></table><!--End Space--><!-- detail --><table align='right' class='table3-3' width='160' border='0' cellspacing='0' cellpadding='0'><tr><td align='center' style='font-family: 'Open Sans', Arial, sans-serif; font-size:13px; color:#7f8c8d; line-height:30px;'><span style='font-weight: bold; color:#91c444;'>联系QQ:</span>11082929 </td></tr></table><!-- end detail --></td></tr><tr><td height='15'></td></tr></table></td></tr></table></td></tr><tr><td height='25'></td></tr><tr><td align='center'><table align='center' bgcolor='#FFFFFF' style='box-shadow: 0px 3px 0px #bdc3c7; border-radius:4px;' width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><table align='center' class='table-inner' width='500' border='0' cellspacing='0' cellpadding='0'><tr><td height='50'></td></tr><!-- title --><tr><td align='center' style='font-family: 'Open Sans', Arial, sans-serif; font-size:30px; color:#3b3b3b; font-weight: bold; '>Yuruisoft综合管理系统-密码找回服务</td></tr><!-- end title --><tr><td align='center'><table width='25' border='0' cellspacing='0' cellpadding='0'><tr><td height='20' style='border-bottom:2px solid #91c444;'></td></tr></table></td></tr><tr><td height='20'></td></tr><!-- content --><tr><td align='center' style='font-family: 'Open Sans', Arial, sans-serif; font-size:13px; color:#7f8c8d; line-height:30px;'>密码修改页面跳转链接:"); #endregion sb.Append("http://" + Request.Url.Host.ToString() + "/UpdatePassWord/ChangePwd?UserName="******"&Vcode=" + Vcode); #region HTML代码B段 sb.Append(@"</td></tr><!-- end content --></table></td></tr><tr><td height='40'></td></tr><!-- button --><tr><td align='center' bgcolor='#ecf0f1'><table align='center' class='table-inner' width='550' border='0' cellspacing='0' cellpadding='0'><tr><td height='30'></td></tr><tr><td align='center'><table class='textbutton' align='center' bgcolor='#91c444' border='0' cellspacing='0' cellpadding='0' style=' border-radius:30px; box-shadow: 0px 2px 0px #dedfdf;'><tr><td height='55' align='center' style='font-family: 'Open Sans', Arial, sans-serif; font-size:16px; color:#7f8c8d; line-height:30px; font-weight: bold;padding-left: 25px;padding-right: 25px;'><a href='"); #endregion sb.Append("http://" + Request.Url.Host.ToString() + "/UpdatePassWord/ChangePwd?UserName="******"&Vcode=" + Vcode); #region HTML代码C段 sb.Append(@"'>点我去修改密码</a> </td> </tr> </table> </td> </tr> <tr> <td height='30'></td> </tr> </table> </td> </tr> <!-- end button --> </table> </td> </tr> <tr> <td height='25'></td> </tr> <tr> <td> <!-- left --> <table bgcolor='#ecf0f1' style='box-shadow:0 3px 0 #bdc3c7;border-radius:4px;' class='table3-3' align='left' width='183' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='text-link' height='50' align='center' style='font-family:'Open Sans',Arial,sans-serif;font-size:14px;color:#3b3b3b;line-height:30px;padding-left:20px;padding-right:20px;'> <a href='#'>其他帮助服务</a> </td> </tr> </table> <!-- end left --> <!--Space--> <table width='1' height='25' border='0' cellpadding='0' cellspacing='0' align='left'> <tr> <td height='25' style='font-size:0;line-height:0;border-collapse:collapse;'> <p style='padding-left:24px;'> </p> </td> </tr> </table> <!--End Space--> <!-- middle --> <table bgcolor='#ecf0f1' style='box-shadow:0 3px 0 #bdc3c7;border-radius:4px;' class='table3-3' align='left' width='183' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='text-link' height='50' align='center' style='font-family:'Open Sans',Arial,sans-serif;font-size:14px;color:#3b3b3b;line-height:30px;padding-left:20px;padding-right:20px;'> <a href='#'>下订单</a> </td> </tr> </table> <!-- end middle --> <!--Space--> <table width='1' height='25' border='0' cellpadding='0' cellspacing='0' align='left'> <tr> <td height='25' style='font-size:0;line-height:0;border-collapse:collapse;'> <p style='padding-left:24px;'> </p> </td> </tr> </table> <!--End Space--> <!-- right --> <table bgcolor='#ecf0f1' style='box-shadow:0 3px 0 #bdc3c7;border-radius:4px;' class='table3-3' align='right' width='183' border='0' cellspacing='0' cellpadding='0'> <tr> <td class='text-link' height='50' align='center' style='font-family:'Open Sans',Arial,sans-serif;font-size:14px;color:#3b3b3b;line-height:30px;padding-left:20px;padding-right:20px;'> <a href='#'>关于我们</a> </td> </tr> </table> <!-- end right --> </td> </tr> <tr> <td height='20'></td> </tr> <tr> <td> <!-- left --> <table align='left' class='table3-3' width='390' border='0' cellspacing='0' cellpadding='0'> <tr> <td style='font-family:'Open Sans',Arial,sans-serif;font-size:12px;color:#ffffff;line-height:30px;'> © 2017 <a href='https://www.yuruisoft.com'>Yuruisoft</a> . All Rights Reserved. </td> </tr> </table> <!-- end left --> <!--Space--> <table width='1' height='25' border='0' cellpadding='0' cellspacing='0' align='left'> <tr> <td height='25' style='font-size:0;line-height:0;border-collapse:collapse;'> <p style='padding-left:24px;'> </p> </td> </tr> </table> <!--End Space--> <table align='right' class='table3-3' width='184' border='0' cellspacing='0' cellpadding='0'> <tr> <td align='center' class='textbutton' style='font-family:'Open Sans',Arial,sans-serif;font-size:12px;color:#ffffff;line-height:30px;'> <a href='https://www.yuruisoft.com'>Yuruisoft.com</a> <span> // </span> <a href='http://www.yurusoft.net'>Yurusoft.net</a> </td> </tr> </table> </td> </tr> <!-- option --> <tr> <td height='60'></td></tr></table></td></tr></table>" ); #endregion mailMsg.Body = sb.ToString();//发送邮件的内容 mailMsg.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); string errMessage = null; EmailCommon.QQEmailSend(mailMsg, "", txtMail, out errMessage); //string errMessage = null; //EmailCommon.sendmail("*****@*****.**", "裕睿软件@Yuruisoft.com", userInfo_EMail, txtName, "Yuruisoft综合系统密码找回服务", sb.ToString(), "", "smtp.qq.com", "*****@*****.**", "nuhurazjakkacbch", out errMessage); return(Content("ok:")); } else { return(Content("no:")); } }
public ActionResult PriceQuotationSendMail(EmailModel model) { if (!ModelState.IsValid) { return(Json(new { Message = @"Gửi email thất bại", Success = false, View = this.RenderPartialView("_EmailFormTemplateView", model) }, JsonRequestBehavior.AllowGet)); } var errorMessages = string.Empty; model.EmailTo = model.EmailTo.Replace(";", ","); foreach (var emailAddress in model.EmailTo.Split(',').Where(x => !string.IsNullOrEmpty(x))) { var errorMessage = string.Empty; if (!emailAddress.IsValid(out errorMessage)) { errorMessages += string.Format("Invalid: {0} Error: {1}", emailAddress, errorMessage); } } if (!string.IsNullOrEmpty(errorMessages)) { ModelState.AddModelError(string.Empty, errorMessages); return(Json(new { Message = @"Gửi email thất bại xem chi tiết lỗi", Success = false, View = this.RenderPartialView("_EmailFormTemplateView", model) }, JsonRequestBehavior.AllowGet)); } var admin = usersServices.FindEntity(x => x.UserName.ToLower() == "admin"); var user = !string.IsNullOrEmpty(CurrenUser.Email) ? CurrenUser : admin; model.User = user; var ccEmail = string.Empty; var dept = usersServices.GetAll( x => x.DeptId == CurrenUser.DeptId && x.RoleName == UsersModel.Positions.Manager.ToString()); ccEmail = dept.Where(u => string.IsNullOrEmpty(u.Email)).Aggregate(ccEmail, (current, u) => current + (u.Email + ",")); model.EmailCc = ccEmail + CurrenUser.Email; var email = new EmailCommon { EmailModel = model }; if (email.SendEmail(out errorMessages, true)) { var emailHistory = new CRMEmailHistoryModel { CcAddress = model.EmailCc, ToAddress = model.EmailTo, Subject = model.Subject, DateSend = DateTime.Now, PriceId = model.IdRef }; emailHistoryService.InsertModel(emailHistory); priceQuotationService.UpdateSendMail(model.IdRef); return(Json(new { Message = @"Gửi email thành công", Success = true }, JsonRequestBehavior.AllowGet)); } ModelState.AddModelError(string.Empty, errorMessages); return(Json(new { Message = @"Gửi email thất bại xem chi tiết lỗi", Success = false, View = this.RenderPartialView("_EmailFormTemplateView", model) }, JsonRequestBehavior.AllowGet)); }
public JsonResult Reply(string blogId, string commentId, string replyId, string nickName, string site, string email, string context) { //TODO 这里要防反复提交,刷评论,DDos攻击之类的 nickName = UrlCommon.Decode(nickName); site = UrlCommon.Decode(site); email = UrlCommon.Decode(email); context = UrlCommon.Decode(context); if (string.IsNullOrWhiteSpace(blogId)) { return(ResponseResult(1, "文章不正确")); } if (string.IsNullOrWhiteSpace(commentId) && string.IsNullOrWhiteSpace(replyId)) { return(ResponseResult(1, "要回复的评论不正确")); } //验证输入的文本 string validateContextResultString = commentApplication.CheckContext(context); if (validateContextResultString != null) { return(ResponseResult(1, validateContextResultString)); } //事务需要对源进行监听,这里从数据库中获取了Blog,需要让事务监听到 try { return(SaidCommon.Transaction(() => { //从数据库检索Blog是否存在 var blog = blogApplication.FindById(blogId.Trim()); if (blog == null) { throw new Exception("用户回复:文章不正确"); } //准备数据 var inputUser = new User { UserID = this.UserId, Name = nickName, Site = site, EMail = email }; Reply toReply = null; Comment comment = null; string toUserEmail = string.Empty; string toUserNickName = string.Empty; if (!string.IsNullOrWhiteSpace(replyId))//如果有针对回复的ID,则以回复ID为准 { toReply = replyApplicaiton.Find(replyId); if (toReply == null) { throw new Exception("用户回复:回复的信息不正确"); } if (toReply.UserId == this.UserId) { throw new Exception("用户不允许回复自己的评论"); } toUserEmail = toReply.User.EMail; toUserNickName = toReply.User.Name; } else //否则以评论ID为准 { comment = commentApplication.Find(commentId); if (comment == null) { throw new Exception("用户回复:回复的评论不正确"); } if (comment.UserId == this.UserId) { throw new Exception("用户不允许回复自己的评论"); } toUserEmail = comment.User.EMail; toUserNickName = comment.User.Name; } User user = null; string validateUserResultString = userApplication.CheckAndTrimInput(inputUser, out user); if (validateUserResultString != null) { return ResponseResult(8, validateUserResultString); } blog.BComment++; blogApplication.Update(blog); //这里拿到的user是已经修剪处理好的user了 userApplication.Update(user); Reply reply = new Reply { BlogId = blog.BlogId, ReplyId = SaidCommon.GUID, CommentId = toReply == null ? comment.CommentId : toReply.CommentId, Context = context, SourceContext = context, Date = DateTime.Now, UserId = user.UserID, ReplyType = toReply == null ? 0 : 1, ToReplyId = toReply == null ? null : toReply.ReplyId }; replyApplicaiton.Add(reply); if (!replyApplicaiton.Commit()) { throw new Exception("用户回复:添加回复对象失败"); } // 发送邮件 EmailCommon.SendReplyEmailAsync(toUserEmail, string.Format("Said - 您在文章《{0}》的评论中收到新的回复", blog.BTitle), context, toUserNickName, string.Format("{2}://{0}/blog/{1}.html?sgs=email-more#comment", Request.Url.Authority, blog.BlogId, Request.Url.Scheme), blog.BTitle, string.Format("{2}://{0}/blog/{1}.html?sgs=email-more#comment", Request.Url.Authority, blog.BlogId, Request.Url.Scheme)); return ResponseResult(new { king = this.AdminId != null, cid = reply == null ? comment.CommentId : reply.CommentId, rid = reply == null ? string.Empty : reply.ReplyId }); })); } catch (Exception e) { logManager.Error("用户评论失败", e); return(ResponseResult(3, "评论失败")); } }
public JsonResult Comment(string blogId, string nickName, string site, string email, string context) { //TODO 这里要防反复提交,刷评论,DDos攻击之类的 nickName = UrlCommon.Decode(nickName); site = UrlCommon.Decode(site); email = UrlCommon.Decode(email); context = UrlCommon.Decode(context); if (string.IsNullOrWhiteSpace(blogId)) { return(ResponseResult(1, "用户评论:文章不正确")); } //验证输入的文本 string validateContextResultString = commentApplication.CheckContext(context); if (validateContextResultString != null) { return(ResponseResult(1, validateContextResultString)); } //事务需要对源进行监听,这里从数据库中获取了Blog,需要让事务监听到 try { return(SaidCommon.Transaction(() => { //从数据库检索Blog是否存在 var blog = blogApplication.FindById(blogId.Trim()); if (blog == null) { throw new Exception("用户评论:文章不正确"); } //准备数据 var inputUser = new User { UserID = this.UserId, Name = nickName, Site = site, EMail = email, //有可能当前用户本来是普通用户,但是管理员新开了页面登录了后台,这样角色的身份就不一样了,这里需要同步把用户角色,并且把用户key同步过去 Rule = this.AdminId != null ? 1 : 0, SecretKey = this.AdminId }; User user = null; string validateUserResultString = userApplication.CheckAndTrimInput(inputUser, out user); if (validateUserResultString != null) { return ResponseResult(8, validateUserResultString); } blog.BComment++; blogApplication.Update(blog); //这里拿到的user是已经修剪处理好的user了 userApplication.Update(user); Comment comment = new Comment { BlogId = blog.BlogId, CommentId = SaidCommon.GUID, Date = DateTime.Now, SourceContext = context, Context = context, UserId = user.UserID }; commentApplication.Add(comment); if (!commentApplication.Commit()) { throw new Exception("用户评论:评论失败"); } // 发送邮件 EmailCommon.SendReplyEmailAsync("*****@*****.**", string.Format("Said - 用户评论了文章《{0}》", blog.BTitle), context, "linkFly", string.Format("{2}://{0}/blog/{1}.html?sgs=email-more#comment", Request.Url.Authority, blog.BlogId, Request.Url.Scheme), blog.BTitle, string.Format("{2}://{0}/blog/{1}.html?sgs=email-more#comment", Request.Url.Authority, blog.BlogId, Request.Url.Scheme)); return ResponseResult(new { king = this.AdminId != null, id = comment.CommentId }); })); } catch (Exception e) { logManager.Error(e); return(ResponseResult(1, "评论失败")); } }