Как отправить электронное письмо исходному отправителю, используя Workflow в Sitecore? - PullRequest
4 голосов
/ 19 мая 2011

Когда элемент отклоняется рецензентом в процессе рабочего процесса, как я могу сообщить об этом отправителю?Это кажется очень распространенной ситуацией, но я просто вижу самые основные поля в элементе «Действие электронной почты»:

Кому, От, Теме, Сообщению

Существует ли системная переменная дляпользователь, а затем что-то для адреса электронной почты пользователя?Я ожидаю, что это будет что-то вроде: $ user.email.

1 Ответ

5 голосов
/ 20 мая 2011

Получите Действие рабочего процесса почты из действий рабочего процесса общего источника.

Затем вам нужно немного расширить контекст Заполнить, чтобы облегчить доступ к последним пользователям.Вот моя реализация одного из наших недавних проектов:

    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 при настройке шаблона электронной почты.

Надеюсь, это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...