You have been redirected from an outdated version of the article.
Below is the content available on this topic. To view the old article click here.
MailTemplate
MailTemplate is a base type that provides configuration parameters and text templates for the User Self-Registration Process and Password Reset.
MailTemplate extends AbstractNode and provides the following additional properties.
Custom MailTemplates can be created and used to send mails in conjunction with the send_plaintext_mail()
and send_html_mail()
functions.
Note: Using MailTemplates is not strictly necessary when using the builtin functions because they accept the text of the mail directly.
Search results for "MailTemplate"
User self-registration
Instead of creating users in the Structr backend manually in the Users and Groups section of Structr’s admin UI, you can allow users to sign-up/self-register. The registration process uses double-opt in by default. All you need is a simple page where new users can enter their e-mail address so Structr can send them an e-mail with a confirmation link.
The following pre-defined MailTemplate keys can be used to configure the self-registration process. In version 4.0 they have been renamed to have a more uniform structure.
Note: The Mail Configuration Settings have to be done for self-registration mails to be sent.
Name | Old Name (removed as of v4.1) | Used as | Default |
CONFIRM_REGISTRATION_SENDER_ADDRESS | SENDER_ADDRESS | The sender address of the registration mail | structr-mail-daemon@localhost |
CONFIRM_REGISTRATION_SENDER_NAME | SENDER_NAME | The sender name of the registration mail | Structr Mail Daemon |
CONFIRM_REGISTRATION_SUBJECT | SUBJECT | The subject of the registration mail | Welcome to Structr, please finalize registration |
CONFIRM_REGISTRATION_TEXT_BODY | TEXT_BODY | The plaintext body of the registration mail | Go to ${link} to finalize registration. |
CONFIRM_REGISTRATION_HTML_BODY | HTML_BODY | The HTML body of the registration mail | <div>Click <a href='${link}'>here</a> to finalize registration.</div> |
CONFIRM_REGISTRATION_BASE_URL | BASE_URL | Used to build the link variable | ${base_url} |
CONFIRM_REGISTRATION_TARGET_PAGE | TARGET_PAGE | the target parameter value for the redirection target page name | register_thanks |
CONFIRM_REGISTRATION_ERROR_PAGE | ERROR_PAGE | the error parameter value for the error redirection target page name | register_error |
Notes:
- The visibility flags of these MailTemplates are ignored because the self-registration mail is created as a privileged user.
- A special
link
variable is provided for the TEXT_BODY
and HTML_BODY
templates and can be output with the usual syntax: ${link}
- Example
link
: https://support.structr.com/confirm_registration?key=<CONFIRM_KEY>&target=/dashboard&onerror=/register-error
- From v4.1 scripting is enabled in two templates:
CONFIRM_REGISTRATION_TEXT_BODY
and CONFIRM_REGISTRATION_TEXT_BODY
. The script is being run in the context of the user (me keyword points to the user).
- In any version prior to 4.1 scripting can not be used and simple text replacement is done
Password Reset
To allow users to regain access to their account when they forgot their password we need to enable them to reset their password.
Note: The Mail Configuration has to be done for password retrieval mails to be sent.
Name | Used as | Default |
RESET_PASSWORD_SENDER_ADDRESS | Sender address | structr-mail-daemon@localhost |
RESET_PASSWORD_SENDER_NAME | Sender name | Structr Mail Daemon |
RESET_PASSWORD_SUBJECT | Subject line | Request to reset your Structr password |
RESET_PASSWORD_TEXT_BODY | Plaintext mail body | Go to ${link} to reset your password. |
RESET_PASSWORD_HTML_BODY | HTML mail body | <div>Click <a href='${link}'>here</a> to reset your password.</div> |
RESET_PASSWORD_BASE_URL | Used to build the link variable | ${base_url} |
RESET_PASSWORD_TARGET_PAGE | target parameter value in the link variable. Specifies the redirect page after successful login. | /reset-password |
Notes:
- The visibility flags of these MailTemplates are ignored because the self-registration mail is created as a privileged user.
- A special
link
variable is provided for the TEXT_BODY
and HTML_BODY
templates and can be output with the usual syntax: ${link}
- Example
link
: https://support.structr.com/reset-password?key=<PASSWORD-RESET-KEY>&target=/reset-password
- From v4.1 scripting is two templates:
RESET_PASSWORD_TEXT_BODY
and RESET_PASSWORD_HTML_BODY
. The script is being run in the context of the user (me keyword points to the user).
- In any version prior to 4.1 scripting can not be used and simple text replacement is done.