Open Closed

Overriding email template for two-factor code #931


User avatar
0
DanielAndreasen created

Im attempting to override existing email templates based on the instructions described in the text templating document and the emailing document.

I was able to override the standard layout by following the instructions in this section (tried both options) but I don't feel like the documentation is very clear on how I should override specific templates such as the one used for sending two-factor codes.

Example of how I have changed the standard layout of emails

.tpl file

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
</head>
<body>
    <h1>This my header</h1>

    {{content}}

    <footer>
      This is my footer...
    </footer>
</body>
</html>

DefinitionProvider.cs

    public class TwoFactorSendCodeDefinitionProvider : TemplateDefinitionProvider, ITransientDependency
    {
        public override void Define(ITemplateDefinitionContext context)
        {
            var emailLayoutTemplate = context.GetOrNull(StandardEmailTemplates.Layout);

            emailLayoutTemplate.WithVirtualFilePath("/Emailing/Templates/TwoFactorSendCoreTemplate.tpl", true);
        }
    }

Result (Password reset)

Issues

I was not able to find the source code of the email template used for sending two-factor codes in any ABP module. I want to know how I can I find this template and how I should override its .tpl file like in the example above.

Im aware of the "Text template management" that is provided with the account module but only a few templates can be edited:

I would also like to know how I should translate the text used in templates. Since I can't find the .tpl files, im unable to view the localization keys I should use to enable translation of emails. "Text template management" shows localization keys for some .tpl files like "PasswordResetLink" but adding these keys to my json localization files in my "Shared" project doesn't affect the emails that are sent.

Project
  • ABP Framework version: v3.3.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no (not tiered)

3 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    hi

    SendSecurityCode does not use a template, I will use a template to send email security code in the next version

  • User Avatar
    0
    DanielAndreasen created

    Hi,

    Thank you for the answer.

    So there is currently no way of customizing the email sent for email security code, even just the translation?

    Also, how about translation of the templates that exists? Should translation simply be done by adding the localization keys to the json file of my own culture, and then the module will pick that up? That doesn't seem to work for me.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    So there is currently no way of customizing the email sent for email security code, even just the translation?

    I have implemented it and it will be available in 4.3.

    You can provide a new email template. Rewrite SendSecurityCodeModel to use this template to send emails.


    Please check this document: https://docs.abp.io/en/abp/latest/Text-Templating#localization

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15