Enable Email to send and receive emails through a custom domain.
There are two parts:
- Your webapp emails users from a custom domain e.g.
no-reply@demo.devlaunchp.ad
. This is used for sending user sign up emails, welcome emails, or any other transactional emails. - Users send emails to a custom domain, which are forwarded to your personal email address e.g.
john.doe@nowhere.example
.
To enable email, you must have already setup your custom domain.
Before you start
AWS requires a custom email domain to be verified before you can send emails.
The AWS email service, SES, is by default in sandbox mode. In sandbox mode, you can only send emails to email addresses you own.
To get out of sandbox mode so your webapp can email anyone on the internet, follow these verification steps.
- Ensure you already setup your Custom domain.
- Go to Get set up in the AWS Console.
- Follow the instructions under Request production access, making sure to select Transactional emails.
You can expect a response from AWS within 24 hours. Once your request is accepted, move onto the next step.
See further details on requesting production access in the AWS documentation.
Configuration
Once your AWS account is out of sandbox mode, enable Email by configuring deployment-params.yml.
EmailEnabled
: set totrue
ForwardingEmailAddress
: emails sent tosupport@yourdomain.com
will be forwarded to this address.
EmailEnabled: true
ForwardingEmailAddress: 'john.doe@nowhere.example'
For email to work, HostedZoneId
and RootDomain
must also be set.
Deployment
Run npm run deploy
.
DevLaunchPad automatically detects the new email settings and configures:
- Sign up emails to send from
no-reply@yourdomain.com
instead ofno-reply@verificationemail.com
(if you've enabled the Sign in feature). - Welcome emails to send to all users after purchase.
- A
pro@yourdomain.com
account for testing. - Email forwarding from
support@yourdomain.com
to the configuredForwardingEmailAddress
.
Customising emails
Emails are defined in serverless/resources/emails in Markdown format.
By default, DevLaunchPad ships with two emails.
- new-user.md sent when a new user is created after purchase (Sign In feature enabled).
- welcome.md sent after purchase (Sign In feature disabled).
You can customise these emails, using variables:
friendlyName
- corresponds toSiteName
in deployment-params.yml.siteBaseURL
- corresponds to your website URL e.g.https://demo.devlaunchp.ad
.
Here's an example welcome email.
Welcome to {{friendlyName}}!
Head over to [the website]({{siteBaseURL}}) when you're ready.
Speak soon,
{{friendlyName}}
Advanced usage
You can send an email from your application any time, using the sendEmail
lambda function defined in serverless.yml.
Execute the lambda function with a JSON body containing these parameters:
emailName
- the simple name of the Markdown file (without extension) defined in serverless/resources/emails e.g.welcome
.subject
- the subject line of the email.toAddress
- the email recipient.
Here's an example body:
{
"emailName": "report",
"subject": "Your PDF report",
"toAddress": "john.doe@nowhere.example"
}
Only use this approach for transactional emails triggered by the user (not marketing emails).
Custom substitutions
Use any key/value pair in your email Markdown by passing a customSubstitutions
object in the JSON body.
For example:
{
"emailName": "report",
"subject": "Your PDF report",
"toAddress": "john.doe@nowhere.example",
"customSubstitutions": {
"city": "London"
}
}
Your markdown can now reference the city
value using {{city}}
syntax.