1

I am using Sitecore 10.3 and working with EXM automated message with "send email campaign message" action in Sitecore forms. I want to receive the message in the language that the user selected in the website.

Example: If the user select English version in website, he receive the message in English and if the user select Arabic version, he receive the message in Arabic version.

what I did in the automated message:

  1. I created 2 version from message Arabic and English
  2. I checked the "use preferred language" checkbox in multi language section

enter image description here

btw I do not have Recipients, the email should be sent to te user who enter his mail in the form.

I am still recieving the message in english, I do not know what I missed, any ideas??

2
  • did you checked doc.sitecore.com/xp/en/developers/exm/101/… Commented Mar 11 at 18:04
  • yes I checked it, I already created multiple version of message arabic and english. my issue is how to send the message version to the user based on current context language that the user selected in the site Commented Mar 12 at 6:47

1 Answer 1

0

The reason why EXM message is not sent in preferred language after form is submitted and "Send email campaign message" action is triggered is quite simple: when contact does that on the website, nothing set preferred language of the contact.

So what happens there? Action is triggered and action creates a contact with values specified in form action editor: enter image description here

But you can only specify there email and consent fields.

When action is triggered, Sitecore attempts to retrieve the contact with given identifier from xDB. If it exists in xDB already, mail is sent. If not, new contact is created using exm.sendEmailSubmitAction/createContact pipeline. But the pipeline only sets EmailAddressList and ConsentInformation facets. It does not update contact language.

After the action has the right contact, it creates new EXM dispatch task.

So how can we make sure that contact has preferred language set?

Well, the answer is most probably not what you want to hear: you have to write a code that will do this for you.

The simplest way to achieve that is create a new submit action that will update contact preferred language which is stored in

contact.GetFacet<PersonalInformation>()?.PreferredLanguage

How to do that? There are so many sources for that information that I'm not going to include the code in this answer. I think the best source is official Sitecore documentation:

https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-manager/walkthrough--creating-a-custom-submit-action-that-updates-contact-details.html

You just need to modify it a bit to include setting preferred language. Something like that should do the trick:

using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
{
    var personalInfo = contact.GetFacet<PersonalInformation>(PersonalInformation.DefaultFacetKey);
    if (personalInfo == null)
    {
        personalInfo = new PersonalInformation();
    }
    // or any other logic to determine preferred language
    personalInfo.PreferredLanguage = Sitecore.Context.Language.Name;
    client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo);

    client.Submit();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.