如何使用Sitecore中的Workflow通过电子邮件发送原始提交者?

时间:2011-05-19 18:57:33

标签: sitecore sitecore6

如果某个项目在工作流程过程中被审核人拒绝,我该如何通知提交者?这似乎是一种非常常见的情况,但我只看到“电子邮件操作”项目中最基本的字段:

To,From,Subject,Message

是否有用户的系统变量,然后是用户的电子邮件地址?我希望它类似于:$ user.email。

1 个答案:

答案 0 :(得分:5)

从共享源工作流操作中获取Mail Workflow Action

然后,您需要稍微扩展Populate上下文,以便更轻松地访问最后的用户。以下是我最近的一个项目的实施:

    protected virtual void PopulateContext(WorkflowPipelineArgs args)
    {
        VelocityContext.Put("args", args);
        var item = args.DataItem;
        VelocityContext.Put("item", item);
        VelocityContext.Put("language", item.Language.CultureInfo.EnglishName);
        VelocityContext.Put("version", item.Version.Number);
        VelocityContext.Put("comment", args.Comments);
        VelocityContext.Put("processor", args.ProcessorItem);
        VelocityContext.Put("user", Context.User);
        Database masterDatabase = Factory.GetDatabase(DatabaseNames.Master);
        var workflow = masterDatabase.WorkflowProvider.GetWorkflow(item);
        var history = workflow.GetHistory(item);
        VelocityContext.Put("history", history);
        if (history.Length > 0)
        {
            string lastUser = history[history.Length - 1].User;
            MembershipUser membership = Membership.GetUser(lastUser);
            VelocityContext.Put("authorEmail",
                                membership != null
                                    ? membership.Email
                                    : DataAccessSettings.Workflow.WebQueryEmail);
        }
        VelocityContext.Put("state", workflow.GetState(item));

        var nextStateItem = GetNextState(args);
        VelocityContext.Put("nextState", nextStateItem != null ? nextStateItem.Name : string.Empty);
        VelocityContext.Put("time", DateTime.Now);
        VelocityContext.Put("previewUrl", string.Format("http://{0}/?sc_itemid=%7b{1}%7d&sc_mode=preview&sc_lang=en", DataAccessSettings.Site.HostName, item.ID.Guid));
        VelocityContext.Put("contentEditorUrl", string.Format("http://{0}/sitecore/shell/Applications/Content%20editor.aspx?fo=%7b{1}%7d&id=%7b{1}%7d&la=en&v=1&sc_bw=1", DataAccessSettings.Site.HostName, item.ID.Guid));
    }

    /// <summary>
    /// Processes the template, expanding all known values
    /// </summary>
    /// <param name="value">Template to process</param>
    /// <returns>Rendered template</returns>
    protected virtual string ProcessValue(string value, Item item)
    {
        var result = new StringWriter();
        try
        {
            Velocity.Evaluate(VelocityContext, result, "Extended mail action", value);
        }
        catch (ParseErrorException ex)
        {
            Log.Error(string.Format("Error parsing template for the {0} item \n {1}",
                                    item.Paths.Path, ex), this);
        }
        return result.GetStringBuilder().ToString();
    }

    #region helpers

    private static Item GetNextState(WorkflowPipelineArgs args)
    {
        Item command = args.ProcessorItem.InnerItem.Parent;
        string nextStateID = command["Next State"];
        if (nextStateID.Length == 0)
        {
            return null;
        }

        return args.DataItem.Database.Items[ID.Parse(nextStateID)];
    }

    private string ProcessFieldValue(string fieldName, Item item)
    {
        string value = item[fieldName];
        if (value.Length > 0)
        {
            return ProcessValue(value, item);
        }
        return value;
    }

    #endregion

您可以在设置电子邮件模板时使用$ authoremail。

希望有所帮助。