如何使用Sitecore中的工作流向原始提交人发送电子邮件?

如何使用Sitecore中的工作流向原始提交人发送电子邮件?,sitecore,sitecore6,Sitecore,Sitecore6,当项目在工作流过程中被审阅者拒绝时,我如何通知提交者?这似乎是一种非常常见的情况,但我只看到“电子邮件操作”项中最基本的字段: 致、自、主题、信息 用户是否有一个系统变量,然后是用户的电子邮件地址?我希望它类似于:$user.email。从共享源工作流操作获取 然后您需要稍微扩展一下填充上下文,以便更容易访问最后的用户。以下是我最近一个项目的实施情况: protected virtual void PopulateContext(WorkflowPipelineArgs args)

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

致、自、主题、信息

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

从共享源工作流操作获取

然后您需要稍微扩展一下填充上下文,以便更容易访问最后的用户。以下是我最近一个项目的实施情况:

    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
受保护的虚拟void PopulateContext(WorkflowPipelineArgs args)
{
VelocityContext.Put(“args”,args);
var item=args.DataItem;
VelocityContext.Put(“项目”,项目);
VelocityContext.Put(“语言”,item.language.CultureInfo.EnglishName);
VelocityContext.Put(“版本”,item.version.Number);
VelocityContext.Put(“注释”,args.Comments);
VelocityContext.Put(“处理器”,args.ProcessorItem);
VelocityContext.Put(“用户”,Context.user);
数据库masterDatabase=Factory.GetDatabase(DatabaseNames.Master);
var workflow=masterDatabase.WorkflowProvider.GetWorkflow(项目);
var history=workflow.GetHistory(项目);
VelocityContext.Put(“历史”,历史);
如果(history.Length>0)
{
字符串lastUser=history[history.Length-1]。用户;
MembershipUser成员资格=membership.GetUser(lastUser);
VelocityContext.Put(“authorEmail”,
成员资格!=null
?会员资格。电子邮件
:DataAccessSettings.Workflow.WebQueryMail);
}
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));
}
/// 
///处理模板,展开所有已知值
/// 
///要处理的模板
///渲染模板
受保护的虚拟字符串ProcessValue(字符串值,项)
{
var result=新的StringWriter();
尝试
{
评估(VelocityContext,结果,“扩展邮件操作”,值);
}
捕获(ParseErrorException ex)
{
Log.Error(string.Format)({0}项的错误分析模板\n{1}),
item.Paths.Path,ex),本);
}
返回结果.GetStringBuilder().ToString();
}
#地区助手
私有静态项GetNextState(WorkflowPipelineArgs args)
{
Item命令=args.ProcessorItem.InnerItem.Parent;
字符串nextStateID=命令[“下一个状态”];
如果(nextStateID.Length==0)
{
返回null;
}
返回args.DataItem.Database.Items[ID.Parse(nextStateID)];
}
私有字符串ProcessFieldValue(字符串字段名,项)
{
字符串值=项[字段名];
如果(value.Length>0)
{
返回过程值(值、项);
}
返回值;
}
#端区
设置电子邮件模板时,可以使用$authoremail


希望能有所帮助。

嗨,我用一个代码示例更新了我的答案。希望有帮助。这看起来真的很有帮助。谢谢这似乎是一个基本特性,我觉得我不需要使用这么多代码。