从工作流程获取审阅者用于电子邮件通知的项

时间:2012-03-07 20:29:25

标签: workflow sitecore

批准或拒绝后,我执行如下所示的自定义电子邮件通知:

public void Process(WorkflowPipelineArgs args)
    {           
        Assert.ArgumentNotNull(args, "args");
        ProcessorItem processorItem = args.ProcessorItem;
        if (processorItem != null)
        {
            //all variables get initialized
            var site = Sitecore.Configuration.Factory.GetSite("website");
            string contentPath = args.DataItem.Paths.ContentPath;               
            var contentItem = args.DataItem;
            var contentWorkflow = contentItem.Database.WorkflowProvider.GetWorkflow(contentItem);
            var contentHistory = contentWorkflow.GetHistory(contentItem);
            var status = "Approved";

            //Get the item from the master database
            var workflowItem = Sitecore.Context.ContentDatabase.Items[args.DataItem.ID];

            //Get the workflow history so that we can email the last person in that chain.
            if (contentHistory.Length > 0)
            {
                //submitting user (string)
                string lastUser = contentHistory[contentHistory.Length - 1].User;
                //sitecore user (so we can get email address)
                var submittingUser = Sitecore.Security.Accounts.User.FromName(lastUser, false);
                //approve/reject comments
                var comments = args.Comments;

                StringBuilder messageBody = new StringBuilder();

                messageBody.AppendFormat("<div style='font-weight:bold'>Domain: {0}</div>", site.HostName);
                messageBody.AppendLine();
                messageBody.AppendFormat("<div style='font-weight:bold'>Content Item: {0}</div>", contentItem.Paths.FullPath);
                messageBody.AppendLine();
                messageBody.AppendFormat("<div style='font-weight:bold'>Status: {0}</div>", status);
                messageBody.AppendLine();                   
                messageBody.AppendFormat("<div style='font-weight:bold'>Approver Comments: {0}</div>", comments);                    

                MailMessage msg = new MailMessage(FromAddress, submittingUser.Profile.Email);
                msg.Subject = string.Format("{0} - Content item has been approved", site.HostName);
                msg.Body = messageBody.ToString();
                SmtpClient smtpClient = new SmtpClient(MailServer);
                smtpClient.Send(msg);
            }
        }
    }

问题:我目前可以获得评论者的评论,但我无法弄清楚如何获取评论者的姓名或电子邮件。

任何想法?

谢谢, ç

1 个答案:

答案 0 :(得分:3)

Sitecore.Context.User可以让您访问点击按钮的用户,这似乎是您正在寻找的。