Make custom SendEmailAfterSubmissionActor culture specific

Vote:
 

Hello everyone,

Though this is my first post here, I've used for some time most of the things found on this forum.

I have a simple question for maybe most of you but somehow tricky for me - I have implemented a custom SendEmailAfterSubmissionActor which is doing what is supposed to do, so no problem so far - the only thing is that I would like to know how can I make the emails specified in the admin interface to be culture specific - yes, I'm aware about the admin part where I can set the culture specific checkbox, but I would like to make through code. I found some vague information that this can be done through an initialization module, but not too much details - is there someone who can guide me a bit please?

Thank you.

#248211
Feb 05, 2021 11:21
Vote:
 

Maybe you could create a custom settings page for storing the email text. The page could be translated to different languages.
In your custom email actor, get the correct language version and send the email?

#248212
Feb 05, 2021 12:26
Evdin Ursan - Feb 05, 2021 13:02
This would be an option but I would complicate the things a little bit because using the email actor (regardless if it's custom or not) you can personalize the email per form - so I can have a message template for a form and another one for another form.
Vote:
 

Hi,

If you wanted to make the whole actor language specific, you can do the equivalent of ticking the culture specific box in admin programmatically in an initialisation module like this:

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class FormsInitialisation : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        var typeRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
        var formContainerType = typeRepo.Load("FormContainerBlock");
        var pdr = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();
        var def = formContainerType.PropertyDefinitions.FirstOrDefault(d => d.Name.Equals("CustomSendEmailAfterSubmissionActor"));
        if (def != null)
        {
            var clone = def.CreateWritableClone();
            clone.LanguageSpecific = true;
            pdr.Save(clone);
        }
    }

    public void Uninitialize(InitializationEngine context)
    {
    }
}

Alternatively, assuming your custom actor has a custom model, you could add an additional property to that model to allow you to define a language then modify your actor to only send emails with a language that matches the current language. That would make it easier to see at a glance which languages have emails defined.

#248218
Feb 05, 2021 13:52
Evdin Ursan - Feb 05, 2021 21:46
Your solution worked perfectly!!! Thank you very much!
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.