Ejemplo n.º 1
0
        public void SendBlogLvmEmail(LeaveMsg lvm)
        {
            //7.1 获取系统邮件Key Secret
            IBLL.IWebSettingService wService = OperateHelper.Current.serviceSession.WebSettingService;
            WebSetting keySeting             = wService.GetDataListBy(w => w.ConfigKey == "SystemEmailKey").FirstOrDefault();
            WebSetting secretSeting          = wService.GetDataListBy(w => w.ConfigKey == "SystemEmailSecret").FirstOrDefault();

            string systemEmailName   = keySeting.ConfigValue;    //系统邮箱
            string systemEmailSecret = secretSeting.ConfigValue; //系统邮箱密码

            //7.2 先取到这条留言的最根上的留言Id
            int      rootlvmId = 0;
            int      parentId  = 0;
            LeaveMsg parentLvm = leaveService.GetDataListBy(c => c.Id == lvm.ParentId).FirstOrDefault();
            LeaveMsg tempLvm   = parentLvm;

            if (parentLvm != null)
            {
                //7.3 父Id
                parentId = parentLvm.Id;
                while (tempLvm != null)
                {
                    tempLvm = leaveService.GetDataListBy(c => c.Id == tempLvm.ParentId).FirstOrDefault();
                    if (tempLvm != null)
                    {
                        parentLvm = tempLvm;
                    }
                }
                rootlvmId = parentLvm.Id;
            }
            else
            {
                rootlvmId = lvm.Id;
            }

            //7.4 url参数;最终这些参数将发送到前台js进行锚点定位、高亮处理
            string url = "http://127.0.0.1:8081/LeaveMsg/Index/"
                         + "?Flag=" + Common.Security.Base64UTF8Encode("1")
                         + "&AnchorLvmRootId=" + Common.Security.Base64UTF8Encode(rootlvmId.ToString())
                         + "&AnchorLvmParentId=" + Common.Security.Base64UTF8Encode(parentId.ToString())
                         + "&AnchorLvmId=" + Common.Security.Base64UTF8Encode(lvm.Id.ToString());//Ajax加载完数据后定位到锚点

            //7.5 构造邮件主题、内容、发送邮件
            Visitor visitor = visitorService.GetEntity(lvm.VisitorId);

            if (lvm.ParentId == 0)
            {
                //给博主的留言
                string subject = "[您的博客有新留言]Re:留言板";

                url += "&Vid=" + Common.Security.Base64UTF8Encode("1");

                Visitor blogger = visitorService.GetEntity(1); //Id=3的是博主=我

                string emailBody = @"#Re: 留言板"
                                   + "<br/>"
                                   + "新留言:"
                                   + "<br/>"
                                   + "内容:" + lvm.LMessage
                                   + "<hr/>"
                                   + "留言者:<a href='#' >" + visitor.VisitorName + "</a>"
                                   + "<br/>"
                                   + "URL:"
                                   + "<a href='" + url + "' title='链接地址'>" + url + "</a>"
                                   + "<br/>"
                                   + "(系统通知,请勿回复)";

                SendMail.SendEMail("smtp.126.com", systemEmailName, systemEmailSecret, blogger.VisitorEmail, subject, emailBody);
            }
            else
            {
                //游客给其它留言者的回复
                LeaveMsg parentlvm = leaveService.GetEntity(lvm.ParentId);

                string toEmail = parentlvm.Visitor.VisitorEmail;
                string subject = "[zynblog留言新回复]Re:";

                url += "&Vid=" + parentlvm.Visitor.Id;

                string emailBody = @"#Re: zynblog留言板"
                                   + "<br/>"
                                   + "<a href='#'>@ </a>" + parentlvm.Visitor.VisitorName
                                   + "<br/>"
                                   + "内容:" + lvm.LMessage
                                   + "<hr/>"
                                   + "回复者:<a href='#' >" + visitor.VisitorName + "</a>"
                                   + "<br/>"
                                   + "URL:"
                                   + "<a href='" + url + "' title='链接地址'>" + url + "</a>"
                                   + "<br/>"
                                   + "(系统通知,请勿回复)";

                SendMail.SendEMail("smtp.126.com", systemEmailName, systemEmailSecret, toEmail, subject, emailBody);
            }
        }
Ejemplo n.º 2
0
        public void SendBlogCmtEmail(Comment cmt, string pageSize)
        {
            //7.1 获取系统邮件Key Secret
            IBLL.IWebSettingService wService = OperateHelper.Current.serviceSession.WebSettingService;
            WebSetting keySeting             = wService.GetDataListBy(w => w.ConfigKey == "SystemEmailKey").FirstOrDefault();
            WebSetting secretSeting          = wService.GetDataListBy(w => w.ConfigKey == "SystemEmailSecret").FirstOrDefault();

            string systemEmailName   = keySeting.ConfigValue;    //系统邮箱
            string systemEmailSecret = secretSeting.ConfigValue; //系统邮箱密码

            //7.2 获取评论隶属于那一篇博文
            string title = articleService.GetEntity(cmt.CmtArtId).Title;

            //7.3 取到这条评论的最根上的评论Id
            int     rootcmtId = 0;
            int     parentId  = 0;
            Comment parentCmt = commentService.GetDataListBy(c => c.Id == cmt.ParentId).FirstOrDefault();
            Comment tempCmt   = parentCmt;

            if (parentCmt != null)
            {
                //7.4 父Id
                parentId = parentCmt.Id;
                while (tempCmt != null)
                {
                    tempCmt = commentService.GetDataListBy(c => c.Id == tempCmt.ParentId).FirstOrDefault();
                    if (tempCmt != null)
                    {
                        parentCmt = tempCmt;
                    }
                }
                rootcmtId = parentCmt.Id;
            }
            else
            {
                rootcmtId = cmt.Id;
            }

            //7.5 判断这个rootcmtId位于第几页
            int pageindex = 0;
            int pagesize  = Convert.ToInt32(pageSize);
            //对所有的一级评论按照时间排序即可
            List <Comment> cmtList = commentService.GetDataListBy(c => c.CmtArtId == cmt.CmtArtId && c.Status == 1 && c.ParentId == 0, c => c.SubTime);
            //判断id为rootcmtId在第几页
            int position = cmtList.FindIndex(c => c.Id == rootcmtId);            //找出这个rootId在所有一级评论中的位置,

            pageindex = Math.Max(((position + 1) + pagesize - 1) / pagesize, 1); //得到的即是该root评论在第几页的

            //7.6 url参数;最终这些参数将发送到前台js进行锚点定位、高亮处理 (对url参数进行加密)
            string url = "http://127.0.0.1:8081/Archives/Index/" + cmt.CmtArtId
                         + "?Flag=" + Common.Security.Base64UTF8Encode("1")
                         + "&AnchorIndex=" + Common.Security.Base64UTF8Encode(pageindex.ToString())
                         + "&AnchorSize=" + Common.Security.Base64UTF8Encode(pageSize.ToString())
                         + "&AnchorCmtRootId=" + Common.Security.Base64UTF8Encode(rootcmtId.ToString())
                         + "&AnchorCmtParentId=" + Common.Security.Base64UTF8Encode(parentId.ToString())
                         + "&AnchorCmtId=" + Common.Security.Base64UTF8Encode(cmt.Id.ToString());

            Visitor visitor = visitorService.GetEntity(cmt.VisitorId);

            //7.7 构造邮件主题、内容、发送邮件
            if (cmt.ParentId == 0)
            {
                string subject = "[您的博客有新评论]Re:" + title;

                url += "&Vid=" + Common.Security.Base64UTF8Encode("1");

                Visitor blogger = visitorService.GetEntity(1); //Id=3的是博主=我

                string emailBody = @"#Re: " + title
                                   + "<br/>"
                                   + "博客新评论:"
                                   + "<br/>"
                                   + "内容:" + cmt.CmtText
                                   + "<hr/>"
                                   + "评论者:<a href='#' >" + visitor.VisitorName + "</a>"
                                   + "<br/>"
                                   + "URL:"
                                   + "<a href='" + url + "' title='链接地址'>" + url + "</a>"
                                   + "<br/>"
                                   + "(系统通知,请勿回复)";

                SendMail.SendEMail("smtp.126.com", systemEmailName, systemEmailSecret, blogger.VisitorEmail, subject, emailBody);
            }
            else
            {
                Comment ParentCmt = commentService.GetEntity(cmt.ParentId);

                string toEmail = ParentCmt.Visitor.VisitorEmail;
                string subject = "[您的博客评论有新回复]Re:" + title;

                url += "&Vid=" + ParentCmt.Visitor.Id;

                string emailBody = @"#Re: " + title
                                   + "<br/>"
                                   + "<a href='#'>@ </a>" + ParentCmt.Visitor.VisitorName
                                   + "<br/>"
                                   + "内容:" + cmt.CmtText
                                   + "<hr/>"
                                   + "回复者:<a href='#' >" + visitor.VisitorName + "</a>"
                                   + "<br/>"
                                   + "URL:"
                                   + "<a href='" + url + "' title='链接地址'>" + url + "</a>"
                                   + "<br/>"
                                   + "(系统通知,请勿回复)";

                SendMail.SendEMail("smtp.126.com", systemEmailName, systemEmailSecret, toEmail, subject, emailBody);
            }
        }