Email templates
Raytha sends nine system emails: account creation, password changes and resets, password recovery and the one-time login code. Each one is an email template you can edit in the admin. This page lists what sends each email and which variables each can use. It also shows how email Liquid differs from the Liquid in page templates.
The templates
Open Email templates in the admin. Each template has a developer name, a Subject and a Message body. The editor lists the variables available to the template you are editing.
| Developer name | Sent when | Extra Target members |
|---|---|---|
raytha_email_admin_welcome | An administrator account is created and the creator chose to send the email. | NewPassword, LoginWithEmailAndPasswordIsEnabled, IsNewlyCreatedUser |
raytha_email_admin_passwordchanged | Someone changes their own password through the change-password flow. Public users go through the same flow, so they receive this email too. | none |
raytha_email_admin_passwordreset | An administrator resets another administrator's password. | NewPassword |
raytha_email_user_welcome | A public user account is created and the email is requested. | NewPassword, LoginWithEmailAndPasswordIsEnabled |
raytha_email_user_passwordchanged | Never. No event uses it, so editing it has no effect. | none |
raytha_email_user_passwordreset | An administrator resets a public user's password. | NewPassword |
raytha_email_login_beginforgotpassword | Someone asks to recover a password. | ForgotPasswordCompleteUrl |
raytha_email_login_completedforgotpassword | The recovery is finished. | none |
raytha_email_login_beginloginwithmagiclink | Someone asks to sign in with a one-time code. | Code, MagicLinkExpiresInSeconds |
You cannot add templates, and you cannot delete or rename these. A template that is edited keeps a list of revisions you can revert to.
What an email template can use
An email renders with two variables, CurrentOrganization and Target. There is no CurrentUser, PathBase, QueryParams or ContentType.
CurrentOrganization
The same object as in page templates: OrganizationName, WebsiteUrl, TimeZone, DateFormat, SmtpDefaultFromAddress, SmtpDefaultFromName, HomePageId, EmailAndPasswordIsEnabledForAdmin, EmailAndPasswordIsEnabledForUsers and AuthenticationSchemes.
Target
Every email carries these members. Not every event fills in all of them.
| Member | Meaning |
|---|---|
Id | The user's id. |
FirstName, LastName, FullName | The name on the account. FullName is the two with a space. |
EmailAddress | The recipient. |
AuthenticationScheme | Developer name of the sign-in method the account uses. |
SsoId | The single sign-on id. Set only by admin_passwordchanged, admin_passwordreset, user_passwordreset and the three login emails. |
IsAdmin | True for an administrator. Set only by the three login emails. It is false in all the others. |
LoginUrl | The sign-in page for the account's kind. Set in the two welcome emails, admin_passwordchanged, admin_passwordreset, user_passwordreset and login_completedforgotpassword. Empty in the other three. |
CustomAttributes | Listed in the editor but never filled in. Do not use it. |
The members in the last column of the table above are added to that email only.
Differences from page templates
- Subject and Message body are rendered separately, each against the same variables. The Subject is Liquid too: the default is
[{{ CurrentOrganization.OrganizationName }}] Password recovery. - Output is not escaped. A name containing
<is written as it is. Pipe names throughescape. - The functions and filters from Functions and filters are defined, but there is no request, so there is little reason to use them in an email.
- The mail is sent as HTML.
Edit one
- Open Email templates and choose the template.
- Change the Subject and the Message body. Use the variables from the table above.
- Save. The next email that event sends uses the new text.
<p>Hi {{ Target.FirstName | default: "there" | escape }},</p>
<p>Someone asked to reset the password for your account at
<a href="{{ CurrentOrganization.WebsiteUrl }}">{{ CurrentOrganization.OrganizationName | escape }}</a>.</p>
<p><a href="{{ Target.ForgotPasswordCompleteUrl }}">Choose a new password</a></p>
<p>If this was not you, you can ignore this email.</p>
Branch on the account kind in the login emails, which are the ones that set IsAdmin:
{% if Target.IsAdmin %}
<p>This is an administrator account.</p>
{% endif %}
Sending
Raytha sends mail over SMTP. If no SMTP host is configured, the email is skipped, nothing fails visibly, and a warning is written to the log. Set up the host, the sender name and the sender address first; see Sending emails. The built-in templates do not accept Cc or Bcc, and Raytha refuses to save either on them, for security reasons. The Cc and Bcc boxes in the editor are not used for sending.
Gotchas
- The welcome and reset emails print
Target.NewPasswordin plain text, because that is how a user learns an assigned password. Keep it, or replace it with a link to your own password recovery page. raytha_email_user_passwordresetandraytha_email_admin_passwordchanged(which public users also receive) setLoginUrlto the administrator sign-in page, not the public one. Write the public sign-in address into the template instead of usingTarget.LoginUrl.Target.ForgotPasswordCompleteUrlandTarget.Codeexpire. The default text says the link lasts 15 minutes. If you change the wording, do not promise a different time.- An error in an email template is not caught when you save it. The error surfaces when the event runs, for example while an administrator is being created. Check a change by triggering the event, for example by resetting the password of a test account.