What would be the best way to send emails based on an email template in code?

I have just seen the example in the community portal on how to send emails from email channels in code, and am shocked on how many lines of code and usages of Kentico services it takes to set up a simple registration confirmation or reset password email based on an email that lives in an email channel.

I am just searching for a simple way to send standard email templates with for example a header and a footer and customizable text within, like in Kentico 13 with the email templates module and the static MailHelper class.

Am I missing something here?

Tags:
Kentico
0

Answers

I ran into this a bit myself. Ultimately, here's the options and pros and cons:

  1. Just do it in a string literal in code. If the email template doesn't really change, and doing a code change/push to update something on it is okay, then just put it in code.

    1. Pro: Easy, you can easily inject variables as you would with any $"{myVal}" type
    2. Con: Not easy to translate
    3. Con: Code push required to make changes
    4. Con: Harder to Localize
  2. You can use Email Templates if you wish, below is a small class i created that let's me parse the properties of a model into the variables in the email template and send

    1. Pro: Also easy to inject variables through the model
    2. Pro: Can update in code
    3. Con: Email Templates weren't exactly 'meant' for this, and I think they may eventually go away.


There's currently a bug with sending code in response, so you can see my email template sender here:

Xperience Email Template Sender - Pastebin.com

0

To response this discussion, you have to login first.