コード例 #1
0
        /// <summary>
        /// 1.0的发送邮件
        /// </summary>
        /// <param name="targetUser"></param>
        /// <param name="user"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public async Task <bool> ReplySendEmail(dynamic toUser, dynamic fromUser, SendEmailType sendEmailType)
        {
            MailAddress MessageFrom = new MailAddress("*****@*****.**"); //发件人邮箱地址
            User        targetUser  = await _userService.GetUserByIdAsync(toUser.UserId);

            User user = await _userService.GetUserByIdAsync(fromUser.UserId);

            string MessageTo      = targetUser.UserEmail; //收件人邮箱地址
            string MessageSubject = "ZswBlog博客回复通知";      //邮件主题
            string Content        = null;                 //目标的内容
            string ReplyContent   = null;                 //回复的内容
            string url            = null;                 //目标地址

            if (sendEmailType == SendEmailType.回复评论)
            {
                //评论回复
                var replyMessage = await _commentService.GetCommentByIdAsync(fromUser.CommentId);

                ReplyContent = replyMessage.Comment1;
                var message = await _commentService.GetCommentByIdAsync(toUser.CommentId);

                Content = message.Comment1;
                int ArticleId = message.ArticleId;
                url = "https://www.zswblog.xyz/details.html?ArticleDetails=" + ArticleId + "";
            }
            else
            {
                //留言回复
                var replyLeacots = await _messageService.GetMessageByIdAsync(fromUser.MessageId);

                ReplyContent = replyLeacots.Message1;
                var leacots = await _messageService.GetMessageByIdAsync(toUser.MessageId);

                Content = leacots.Message1;
                url     = "https://www.zswblog.xyz/leacots.html";
            }
            //邮件内容 (一般是一个网址链接,生成随机数加验证id参数,点击去网站验证。)//请把这个参数改成你自己的
            string MessageBody = "<div id=\"contentDiv\" onmouseover=\"getTop().stopPropagation(event);\" onclick=\"getTop().preSwapLink(event, 'spam', 'ZC3011-yZb5lAAS2SKCSSF8palnY9a');";

            MessageBody += "style=\"position: relative; font - size:14px; height: auto; padding: 15px 15px 10px 15px; z - index:1; zoom: 1; line - height:1.7; \"";
            MessageBody += "class=\"body\"><div id=\"qm_con_body\"><div id=\"mailContentContainer\" class=\"qmbox qm_con_body_content qqmail_webmail_only\" >";
            MessageBody += "<div style=\"position: relative; color:#555;font:12px/1.5 Microsoft YaHei,Tahoma,Helvetica,Arial,sans-serif;max-width:600px;margin:50px auto;border-radius: 5px;box-shadow:0 5px 10px #aaaaaa;background: 0 0 repeat-x #FFF;background-image: -webkit-repeating-linear-gradient(135deg, #4882CE, #4882CE 20px, #FFF 20px, #FFF 35px, #EB1B2E 35px, #EB1B2E 55px, #FFF 55px, #FFF 70px);background-image: repeating-linear-gradient(-45deg, #4882CE, #4882CE 20px, #FFF 20px, #FFF 35px, #EB1B2E 35px, #EB1B2E 55px, #FFF 55px, #FFF 70px);background-size: 100% 10px\">";
            MessageBody += "<div style=\"padding: 0 15px 8px;\"><h2 style=\"border-bottom:1px solid #e9e9e9;font-size:18px;font-weight:normal;padding:20px 0 10px;\"><span style=\"color: #12ADDB\">&gt;";
            MessageBody += "</span>您在 <a style=\"text - decoration:none; color: #12ADDB;\" href=\"https://www.zswblog.xyz\" target=\"_blank\" rel=\"noopener\">张晟玮博客</a> 中的评论或留言有新回复啦!</h2><div style=\"font-size:14px;color:#777;padding:0 10px;margin-top:18px\">";
            MessageBody += "<p>" + targetUser.UserName + ",您曾在张晟玮博客中发表评论或留言:</p><div style=\"background-color:#f5f5f5;padding:10px 15px;margin:18px 0;\">" + Content + "</div><p>" + user.UserName + "回复说:</p><div style=\"background-color:#f5f5f5;padding: 10px 15px;margin:18px 0;\">" + ReplyContent + "</div>";
            MessageBody += "<p>您可以点击<a style=\"text - decoration:none; color:#12addb\" href=" + url + " title=\"点击查看完整的回复内容\" target=\"_blank\" rel=\"noopener\">查看完整的回复內容</a>,欢迎回访<a style=\"text - decoration:none; color:#12addb\" href=\"https://www.zswblog.xyz\" target=\"_blank\" rel=\"noopener\">张晟玮的博客</a>!</p>";
            MessageBody += "</div></div><div style=\"color:#888;padding:10px;border-top:1px solid #e9e9e9;background:#f5f5f5;border-radius: 0 0 5px 5px;\">";
            MessageBody += "<p style=\"margin: 0; padding: 0; \">Copyright ©<span style=\"border - bottom - width: 1px; border - bottom - style: dashed; border - bottom - color: rgb(204, 204, 204); z - index: 1; position: static; \"><span";
            MessageBody += "style=\"border - bottom:1px dashed #ccc;z-index:1\" t=\"7\" onclick=\"return false;\" data=\"2019-2019\">2019-2019</span>";
            MessageBody += "</span><a style=\"color:#888;text-decoration:none;\" href=\"https://www.zswblog.xyz\" target=\"_blank\" rel=\"noopener\">张晟玮的博客</a>- 本邮件自动生成,请勿直接回复!</p>";
            MessageBody += "</div></div><style type=\"text/css\">.qmbox style,.qmbox script,.qmbox head,.qmbox link,.qmbox meta {display: none !important;}</style></div></div>";
            MessageBody += "<style>#mailContentContainer .txt {height: auto;}</style></div>";
            return(SendMail(MessageFrom, MessageTo, MessageSubject, MessageBody));
        }
コード例 #2
0
ファイル: EmailUtility.cs プロジェクト: sumit002/EZone.Wpf
        public static string GetEmailMessage(SendEmailType emailType, Dictionary <string, string> placeHolders)
        {
            var emailTypeConfig = EmailConfig.ReadConfiguration().EmailTypes.FirstOrDefault(m => m.Name == emailType.ToString());

            string mailbody = string.Empty;

            using (StreamReader reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, emailTypeConfig.HtmlContentFile)))
            {
                mailbody = reader.ReadToEnd();
            }
            return(ReplaceMessagePlaceHolders(mailbody, placeHolders));
        }
コード例 #3
0
ファイル: XmlConfig.cs プロジェクト: liwendiao123/srclwd
 /// <summary>
 /// 获取Email格式XML的节点
 /// </summary>
 /// <param name="ToUse">用途标记,ToUse节点内容</param>
 /// <returns></returns>
 public static XmlConfig_Email GetEmailConfig(SendEmailType toUse)
 {
     string filename = GetMapPath(EMAIL_PATH);
     XElement xml = XElement.Load(filename);
     XElement configNode = xml.Elements("MailConfig").First(z => z.Element("ToUse").Value == toUse.ToString());
     return new XmlConfig_Email()
     {
         ToUse = configNode.Element("ToUse").Value,
         Subject = configNode.Element("Subject").Value,
         Body = configNode.Element("Body").Value,
         Holders = configNode.Element("Holders").Value,
         UpdateTime = DateTime.Parse(configNode.Element("UpdateTime").Value)
     };
 }
コード例 #4
0
        /// <summary>
        /// 针对评论留言的发送邮件
        /// </summary>
        /// <param name="to"></param>
        /// <param name="from"></param>
        /// <param name="sendEmailType"></param>
        /// <returns></returns>
        public bool ReplySendEmail(dynamic to, dynamic from, SendEmailType sendEmailType)
        {
            var     messageFrom    = new MailAddress(SendEmailAddress); //发件人邮箱地址
            UserDTO targetUser     = UserService.GetUserByIdAsync(to.userId);
            UserDTO user           = UserService.GetUserByIdAsync(from.userId);
            var     messageTo      = targetUser.email;    //收件人邮箱地址
            var     messageSubject = SiteName + "博客回复通知"; //邮件主题
            string  content;                              //目标的内容
            string  replyContent;                         //回复的内容
            var     url = ReturnBackUrl;                  //目标地址

            if (sendEmailType == SendEmailType.回复评论)
            {
                //评论回复
                var replyMessage = CommentService.GetCommentByIdAsync(from.id);
                replyContent = replyMessage.content;
                var message = CommentService.GetCommentByIdAsync(to.id);
                content = message.content;
                int articleId = message.articleId;
                url += "/details/" + articleId;
            }
            else
            {
                //留言回复
                var replyMessage = MessageService.GetMessageByIdAsync(from.id);
                replyContent = replyMessage.content;
                var message = MessageService.GetMessageByIdAsync(to.id);
                content = message.content;
                url    += "/leacots";
            }
            //邮件内容
            var messageBody = "<div id=\"contentDiv\" onmouseover=\"getTop().stopPropagation(event);\" onclick=\"getTop().preSwapLink(event, 'spam', 'ZC3011-yZb5lAAS2SKCSSF8palnY9a');";

            messageBody += "style=\"position: relative; font - size:14px; height: auto; padding: 15px 15px 10px 15px; z - index:1; zoom: 1; line - height:1.7; \"";
            messageBody += "class=\"body\"><div id=\"qm_con_body\"><div id=\"mailContentContainer\" class=\"qmbox qm_con_body_content qqmail_webmail_only\" >";
            messageBody += "<div style=\"position: relative; color:#555;font:12px/1.5 Microsoft YaHei,Tahoma,Helvetica,Arial,sans-serif;max-width:600px;margin:50px auto;border-radius: 5px;box-shadow:0 5px 10px #aaaaaa;background: 0 0 repeat-x #FFF;background-image: -webkit-repeating-linear-gradient(135deg, #4882CE, #4882CE 20px, #FFF 20px, #FFF 35px, #EB1B2E 35px, #EB1B2E 55px, #FFF 55px, #FFF 70px);background-image: repeating-linear-gradient(-45deg, #4882CE, #4882CE 20px, #FFF 20px, #FFF 35px, #EB1B2E 35px, #EB1B2E 55px, #FFF 55px, #FFF 70px);background-size: 100% 10px\">";
            messageBody += "<div style=\"padding: 0 15px 8px;\"><h2 style=\"border-bottom:1px solid #e9e9e9;font-size:18px;font-weight:normal;padding:20px 0 10px;\"><span style=\"color: #12ADDB\">&gt;";
            messageBody += "</span>您在 <a style=\"text - decoration:none; color: #12ADDB;\" href=" + SiteUrl + " target =\"_blank\" rel=\"noopener\">" + SiteName + "博客</a> 中的评论或留言有新回复啦!</h2><div style=\"font-size:14px;color:#777;padding:0 10px;margin-top:18px\">";
            messageBody += "<p>" + targetUser.nickName + ",您曾在" + SiteName + "博客中发表评论或留言:</p><div style=\"background-color:#f5f5f5;padding:10px 15px;margin:18px 0;\">" + content + "</div><p>" + user.nickName + "回复说:</p><div style=\"background-color:#f5f5f5;padding: 10px 15px;margin:18px 0;\">" + replyContent + "</div>";
            messageBody += "<p>您可以点击<a style=\"text - decoration:none; color:#12addb\" href=" + url + " title=\"点击查看完整的回复内容\" target=\"_blank\" rel=\"noopener\">查看完整的回复內容</a>,欢迎回访<a style=\"text - decoration:none; color:#12addb\" href=" + SiteUrl + " target=\"_blank\" rel=\"noopener\">" + SiteName + "的博客</a>!</p>";
            messageBody += "</div></div><div style=\"color:#888;padding:10px;border-top:1px solid #e9e9e9;background:#f5f5f5;border-radius: 0 0 5px 5px;\">";
            messageBody += "<p style=\"margin: 0; padding: 0; \">Copyright ©<span style=\"border - bottom - width: 1px; border - bottom - style: dashed; border - bottom - color: rgb(204, 204, 204); z - index: 1; position: static; \"><span";
            messageBody += "style=\"border - bottom:1px dashed #ccc;z-index:1\" t=\"7\" onclick=\"return false;\" data=\"2019-2019\">2019-2020</span>";
            messageBody += "</span><a style=\"color:#888;text-decoration:none;\" href=" + SiteUrl + " target=\"_blank\" rel=\"noopener\">" + SiteName + "博客</a>- 本邮件自动生成,请勿直接回复!</p>";
            messageBody += "</div></div><style type=\"text/css\">.qmbox style,.qmbox script,.qmbox head,.qmbox link,.qmbox meta {display: none !important;}</style></div></div>";
            messageBody += "<style>#mailContentContainer .txt {height: auto;}</style></div>";
            return(SendMail(messageFrom, messageTo, messageSubject, messageBody));
        }
コード例 #5
0
 public SendEmailAttribute(SendEmailType type)
 {
     this.EmailType = type;
 }
コード例 #6
0
ファイル: EmailUtility.cs プロジェクト: sumit002/EZone.Wpf
 public EmailParams(string toMail, SendEmailType emailType, Dictionary <string, string> placeHolders, string ccMail = null, string mailAttachments = null)
     : this(toMail, ccMail, null, EmailUtility.GetEmailSubject(emailType, placeHolders), EmailUtility.GetEmailMessage(emailType, placeHolders), null, null, mailAttachments)
 {
 }
コード例 #7
0
ファイル: EmailUtility.cs プロジェクト: sumit002/EZone.Wpf
        public static string GetEmailSubject(SendEmailType emailType, Dictionary <string, string> placeHolders)
        {
            var emailTypeConfig = EmailConfig.ReadConfiguration().EmailTypes.FirstOrDefault(m => m.Name == emailType.ToString());

            return(ReplaceMessagePlaceHolders(emailTypeConfig.Subject, placeHolders));
        }
コード例 #8
0
ファイル: EmailSender.cs プロジェクト: Ivanhuan/Clubs
        public Task SendEmailAsync(string ToEmail, string Subject, string BodyMsg, SendEmailType type = SendEmailType.其他)
        {
            if (type == SendEmailType.其他)
            {
            }
            else if (type == SendEmailType.注册验证码)
            {
                string[] s1 = ToEmail.Split('@');
                if (s1.Length > 2)
                {
                    throw new Exception("邮箱" + ToEmail + "格式非法");
                }
                string s10    = s1[0];
                string email2 = "";
                if (s10.Length > 4)
                {
                    email2  = s10.Substring(0, 2);
                    email2 += "*****";
                    email2 += s10.Substring(s10.Length - 2, 2);
                }
                else
                {
                    email2 = s10;
                }
                email2 += "@" + s1[1];
                BodyMsg = CreateEmailBody(email2, BodyMsg);
            }
            //MailMessage mailobj = new MailMessage();
            MailMessage mailMsg = new MailMessage
            {
                From = new MailAddress("*****@*****.**", "一人之下"),
                //From = new MailAddress("*****@*****.**", "一人之下"),//源邮件地址和发件人
                Subject    = Subject,                 //发送邮件的标题
                Body       = BodyMsg,                 //发送邮件的内容
                IsBodyHtml = true,
            };                                        //实例化对象

            mailMsg.To.Add(new MailAddress(ToEmail)); //收件人地址
                                                      //指定smtp服务地址(根据发件人邮箱指定对应SMTP服务器地址)
                                                      //SmtpClient client = new SmtpClient
                                                      //{
                                                      //    UseDefaultCredentials=false,
                                                      //    Host = "smtp.qq.com",
                                                      //    //要用587端口
                                                      //    Port = 587,
                                                      //    //加密
                                                      //    EnableSsl = true,
                                                      //    //通过用户名和密码验证发件人身份
                                                      //    Credentials = new NetworkCredential("*****@*****.**", "uxtktpyxkdwrhihc")
                                                      //};
            SmtpClient client = new SmtpClient
            {
                UseDefaultCredentials = false,
                Host        = "smtp.searching-info.com",
                Port        = 25,
                EnableSsl   = true,
                Credentials = new NetworkCredential("*****@*****.**", "init123456")
            };

            return(client.SendMailAsync(mailMsg));
        }
コード例 #9
0
        public Task SendEmailAsync(string ToEmail, string Subject, string BodyMsg, SendEmailType type = SendEmailType.其他)
        {
            if (type == SendEmailType.其他)
            {
            }
            else if (type == SendEmailType.注册验证码)
            {
                string[] s1 = ToEmail.Split('@');
                if (s1.Length > 2)
                {
                    throw new Exception("邮箱" + ToEmail + "格式非法");
                }
                string s10    = s1[0];
                string email2 = "";
                if (s10.Length > 4)
                {
                    email2  = s10.Substring(0, 2);
                    email2 += "*****";
                    email2 += s10.Substring(s10.Length - 2, 2);
                }
                else
                {
                    email2 = s10;
                }
                email2 += "@" + s1[1];
                BodyMsg = CreateEmailBody(email2, BodyMsg);
            }
            //MailMessage mailobj = new MailMessage();
            MailMessage mailobj = new MailMessage();

            //{
            //    From = "*****@*****.**",
            //    //From = new MailAddress("*****@*****.**", "一人之下"),//源邮件地址和发件人
            //    Subject = Subject,//发送邮件的标题
            //    Body = BodyMsg,//发送邮件的内容
            //    BodyFormat=MailFormat.Html
            //};//实例化对象
            //mailMsg.To = ToEmail;
            //指定smtp服务地址(根据发件人邮箱指定对应SMTP服务器地址)
            //SmtpMail.Send(mailMsg);
            //return client.SendMailAsync(mailMsg);

            ////QQ邮箱
            //mailobj.From = new MailAddress("*****@*****.**");
            //mailobj.To.Add(new MailAddress("*****@*****.**"));
            //mailobj.Priority = MailPriority.Normal;
            //mailobj.Subject = "测试邮件发送";
            //mailobj.Body = "正文发送的地方";
            //mailobj.IsBodyHtml = false;
            //SmtpClient sc = new SmtpClient();
            //sc.Host = "smtp.qq.com";
            //sc.Port = 465;
            //sc.EnableSsl = true;
            //sc.UseDefaultCredentials = false;
            //sc.Credentials = new NetworkCredential("*****@*****.**", "hkefwggvoagwgigj");
            //sc.Send(mailobj);
            //ViewBag.Res = "发送成功";

            mailobj.To         = ToEmail;
            mailobj.From       = "*****@*****.**";
            mailobj.Subject    = Subject;
            mailobj.BodyFormat = MailFormat.Html;
            mailobj.Body       = BodyMsg;

            mailobj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");            //身份验证
            mailobj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailobj.From);       //邮箱登录账号,这里跟前面的发送账号一样就行
            mailobj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xhqwqsvywgxtjaee"); //这个密码要注意:如果是一般账号,要用授权码;企业账号用登录密码
            mailobj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);              //端口
            mailobj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");               //SSL加密
            SmtpMail.SmtpServer = "smtp.qq.com";                                                                   //企业账号用smtp.exmail.qq.com
            //SmtpMail.Send(mailobj);

            return(Task.Run(() => SmtpMail.Send(mailobj)));
        }
 private static string GetDefaultMacrosValue(SendEmailType sendEmailType, string macros)
 {
     return(sendEmailType == SendEmailType.Auto
                         ? string.Empty
                         : GetHighlightedMacros(macros));
 }
コード例 #11
0
        public static void SendEmail(int actionId, DateTime date)
        {
            try
            {
                var           sendEmailStr = System.Configuration.ConfigurationManager.AppSettings["SendEmail"];
                SendEmailType sendEmail    = SendEmailType.Always;
                if (!Enum.TryParse <SendEmailType>(sendEmailStr, out sendEmail))
                {
                    // parsing failed, abort sending
                    return;
                }
                if (sendEmail == SendEmailType.Never)
                {
                    return;
                }

                //Create body
                StringBuilder sb                 = new StringBuilder();
                var           erpActionStep      = DataWriter.GetActionSteps(actionId);
                var           maxIteration       = erpActionStep.Max(x => x.iteration);
                var           lastIterationSteps = erpActionStep.Where(x => x.iteration == maxIteration).ToList();
                bool          success            = lastIterationSteps.Count(x => x.Success.HasValue && x.Success.Value) == lastIterationSteps.Count;
                if (sendEmail == SendEmailType.Always || (sendEmail == SendEmailType.OnError && !success))
                {
                    var environment = System.Configuration.ConfigurationManager.AppSettings["NotificationEnvironment"];
                    sb.AppendLine(string.Format("The D365 transfer started at {0} on environment <b>{2}</b> was a <b>{1}</b>,", date, success ? "success" : "failure", environment));
                    sb.AppendLine(string.Format("for the action id:{0}<br>", actionId));


                    if (!success)
                    {
                        sb.AppendLine("The following steps failed:<br>");
                        sb.AppendLine(CreateErrorBody(erpActionStep.Where(x => x.Success.HasValue && x.Success.Value == false).ToList()));
                    }


                    var         emailFromAddress  = "*****@*****.**";
                    var         emailToAddresses  = System.Configuration.ConfigurationManager.AppSettings["NotificationEmailAddresses"];
                    string[]    emailAddressArray = emailToAddresses.Split(',');
                    MailAddress emailFrom         = new MailAddress(emailFromAddress);
                    foreach (var email in emailAddressArray)
                    {
                        MailAddress emailTo = new MailAddress(email);
                        MailMessage mail    = new MailMessage(emailFrom, emailTo);
                        mail.ReplyToList.Add(new MailAddress("*****@*****.**"));
                        SmtpClient        client = new SmtpClient();
                        NetworkCredential c      = new NetworkCredential(emailFromAddress, "!ErpNotification2019");

                        client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Host        = "smtp.office365.com";
                        client.Credentials = c;
                        client.EnableSsl   = true;
                        client.Port        = 587;
                        mail.Subject       = "D365 Datatransfer status";
                        mail.Body          = sb.ToString();
                        mail.IsBodyHtml    = true;
                        client.Send(mail);
                    }
                }
            }
            catch (Exception e)
            {
                DataWriter.LogError(e.Message, e.StackTrace, "Email Sender", e.HResult);
            }
        }