Skip to main content

Choosing SendGrid Templates for Email Authentication with Optional Additional Languages

Assign a SendGrid template to each authentication email, add per-language templates, and use brainCloud's template variables

Written by Jason Liang

When your app uses rich email service templates, brainCloud sends its authentication emails through your own SendGrid account, using templates that you design in SendGrid. This article explains how to choose which SendGrid template is used for each kind of email, how to provide different templates for different languages, and which variables brainCloud fills in for you.

These settings are on the Rich Email Service Templates tab of the App > Design > Authentication > Email Authentication page.

Before you start

  • The SendGrid integration is configured and enabled on App > Design > Integrations > Manage Integrations. Your SendGrid API key needs Mail Send (full) and Template Engine (read) permissions; without Template Engine access, brainCloud can't list your templates.

  • On the Email Authentication tab, Send Verification Email Using SendGrid is checked and Authentication Templates is set to Use rich email service templates (recommended). The Rich Email Service Templates tab is disabled while Use simple plain text is selected.

  • You have created your templates in the SendGrid dashboard (Email API > Dynamic Templates). Dynamic templates are recommended.

Step 1: Assign a template to each use case

The tab shows one dropdown for each email brainCloud can send:

  • Delete Account: sent when a user requests that their account be deleted. It contains the confirmation link.

  • Password Reset: sent when a user requests a password reset. It contains the reset link.

  • Password Reset Confirmation: sent after the password has been changed, if Send Password Reset Confirmation Email is enabled.

  • User Locked: sent when login brute-force protection locks an account, if notifications are enabled on App > Design > Security > User.

  • Verification Email: sent when a user registers an email identity. It contains the verification link.

  • Verification Email Confirmation: sent after the user verifies, if Send Confirmation Email is enabled.

Each dropdown lists the templates in your SendGrid account by name; both dynamic and legacy templates are included. Choose the template for each email, then click Save.

Tip: Click Test next to any dropdown to send the selected template to the email address of your portal login. Test emails use sample values (for example, userName jDoe), so only the basic variables are filled in.

Step 2 (optional): Add templates for other languages

You can send users a template in their own language:

  1. Make sure the language is enabled for your app on App > Design > Core App Info > Localization. The Add... dialog only offers the app's supported languages.

  2. On the Rich Email Service Templates tab, click + Add... next to Language and choose one or more languages.

  3. Choose a language in the Language dropdown. The template dropdowns now show the assignments for that language.

  4. Assign a SendGrid template (for example, a translated copy such as Password Reset – FR) to each email, then click Save.

To remove a language, select it and click Delete.... The app's default language can't be deleted.

How brainCloud picks the template

  • brainCloud uses the language code on the user's profile, which is normally set by the client SDK from the device language when the user authenticates. If the profile has no language, brainCloud uses the app's default language.

  • If no template is assigned for that language, brainCloud falls back to the English (en) template.

Recommendation: always assign templates for English, even if your app's default language is something else. Then every user receives an email, even when their language has no template of its own.

Step 3: Use brainCloud's variables in your templates

brainCloud passes user and app details to SendGrid with every email. How you reference them depends on the type of template:

  • Dynamic templates (template ID starts with d-) use Handlebars syntax, for example {{appName}} and {{webUrl}}.

  • Legacy templates use dash-wrapped substitution tags, for example -appName- and -webUrl-.

Variable

Value

webUrl

The action link. It is provided only for Verification Email, Password Reset and Delete Account, and these templates must include it.

appName, appIcon

Your app's name and icon URL

profileId, userName, userEmail

The user's profile ID, name and email address

userCountryCode, userLanguage

The user's country and language codes

icon

The user's profile picture URL

lastLogin, accountCreated, loginCount

Login history (ISO-8601 timestamps and a count)

amountSpent, XPLevel, XPPoints

The user's spend and XP statistics

virtualCurrency_<name>

The user's balance of each virtual currency, for example virtualCurrency_gems

homepageUrl, feedbackUrl, exitSurveyUrl, customerServiceUrl, termsAndConditionsUrl, privacyUrl, address, city, state, country, zip

Your branding and contact details, provided only when Self-Service branding is enabled for the app

Example dynamic template snippet for the password reset email:

<p>Hi {{userName}},</p>
<p>We received a request to reset your {{appName}} password.</p>
<p><a href="{{webUrl}}">Reset my password</a></p>

Troubleshooting

  • The dropdowns are empty: check that the SendGrid integration is enabled and that the API key has Template Engine (read) permission.

  • A user received the English email instead of their language: check the language code on their profile (User > User Summary), and make sure a template is assigned for that exact language.

  • Links are missing from the email: make sure the template uses {{webUrl}} (dynamic) or -webUrl- (legacy), and that it is assigned to Verification Email, Password Reset or Delete Account.

Did this answer your question?