Dynamically Customize the 'From' Address in Email Templates
Last Updated:
Overview
This article describes how to dynamically modify the 'From' address used in Email Templates and the limitations of this method.
Applies To
- Email Templates
Solution
It is possible to include common variables using the Liquid syntax. For example, use application.client_metadata.KeyValueHere for custom values on a per-application basis. It is not possible to set the entire ‘From’ field to such a variable.
- For example,
{{application.name}}will not work, but{{application.name}}@[invalid URL removed]will.
Customers can also use their own custom provider and handle the email sending flow entirely using the "onExecuteCustomEmailProvider" action.
- Example with Amazon Simple Email Service (SES):
exports.onExecuteCustomEmailProvider = async (event, api) => { onst client = new SESClient({ credentials: { accessKeyId: event.secrets.AWS_ACCESS_KEY_ID, secretAccessKey: event.secrets.AWS_SECRET_ACCESS_KEY, }, region: event.secrets.AWS_REGION || 'us-east-1', }); const command = new SendEmailCommand({ Destination: { ToAddresses: [event.notification.to], }, Message: { Body: { Html: { Charset: 'UTF-8', Data: event.notification.text, }, }, Subject: { Charset: 'UTF-8', Data: event.notification.subject, }, }, Source: event.notification.from, }); try { await client.send(command); return; } catch (error) { console.error('Error sending email via AWS SES:', error); return error; } };