Comment on page
Email Notifications
You can send email notifications to your users from anywhere in your application.
Emails use a JSON template for content - no need to wrestle with HTML tables. The JSON is then injected into an email template located in the
/emails
directory.await mail.send({
to: 'name@email.com,
template: 'welcome',
content: {
name: 'John',
plan: 'startup',
price: '$49'
}
});
You can also use a custom HTML template by passing the file name as a
custom
value.If you wish to send a notification to yourself, you can use the mail utility endpoint:
POST /api/utility/mail
// params
{
name: 'from-name',
email: 'from-email-address',
message: 'message body'
}
This will send an email to the address stored in
SUPPORT_EMAIL
environment variable. You can see an example of this in the /help view. If you wish to use another mail provider, you can simply install the nodemailer transport package for your chosen service and update the
mail.send
method in helper/mail
.- 1.
- 2.Change the require import on line 7 of helper/mail to import your package
- 3.Update the authentication object in line 25 of helper/mail to match your service's requirements
const mailgun = require('nodemailer-mailgun-transport'); // require transport
exports.send = async function(data){
// transport auth
const transport = nodemailer.createTransport(mailgun({
host: settings.host,
auth: {
api_key: process.env.MAILGUN_API_KEY,
domain: settings.domain
}))
}
Gravity includes a clean, responsive email template, but you can also add your own templates to cover a wider variety of use cases.
I recommend using htmlemail.io for premium templates. Gravity customers get 20% OFF – you’ll receive a coupon via email after you purchase.
For full instructions on how to implement a custom template, please follow the instructions in this blog post.
If you're migrating from a previous version of Gravity, please run the seeds below to populate the database with the email content.
knex seed:run // sql
node seed/mongo // mongodb
Last modified 2mo ago