Gravity
  • Welcome to Gravity
  • Getting Started
  • Stack
  • Updates
  • Rules For AI
  • Troubleshooting
  • Gravity Server
    • Introduction
    • Installation
      • Install Node.js
      • Database Setup
      • Stripe Setup
      • Mailgun Setup
      • Install Gravity
    • Application Structure
    • REST API
      • API Scopes
      • Webhooks
    • Authentication
      • Email Verification
      • Social Sign On
      • Two-Factor Authentication
    • Authorization
      • Feature Access and Plan Restrictions
      • Permissions (Roles)
    • Config
    • Environment Variables
    • Database Queries
    • Handling Errors
    • Logging
    • Localization
    • Push Notifications
    • Email Notifications
    • User Feedback
    • User Onboarding
    • File Uploads
    • Billing
      • Seat Billing
      • Usage Billing
    • Free Accounts
    • CLI Toolbelt
    • Testing
    • AI Tools
    • Background Jobs
    • Deployment
  • Gravity Web
    • Introduction
    • Tailwind & SCSS
    • Routing
    • Events
    • Authentication
    • Localization
    • Hooks
      • useAPI
      • usePlans
      • usePermissions
    • Components
      • Alert
      • Animate
      • Avatar
      • Badge
      • Breadcrumb
      • Button
      • Calendar
      • Card
      • Chart
      • Checklist
      • Credit Card
      • Detail
      • Dialog
      • Dropdown
      • Feedback
      • Form
      • Grid
      • Header
      • Helper
      • Icon
      • Image
      • Layout
      • Link
      • List
      • Loader
      • Logo
      • Nav
      • Onboarding
      • Pagination
      • Popover
      • Progress
      • Row
      • Search
      • Separator
      • Sheet
      • Social
      • Stat
      • Table
      • Tabs
      • Toast (Notification)
      • Tooltip
      • User
      • View
    • Views
    • Handling Errors
    • Deployment
  • Gravity Native
    • Introduction
    • Prerequisites
    • Installation
    • App Context
    • Authentication
    • Localisation
    • External Linking
    • Handling Errors
    • Navigation
    • Config
    • Events
    • Views
    • Components
      • Badge
      • Blankslate
      • Button
      • Card
      • Chart
      • Form
      • Global
      • Grid
      • Icon
      • List
      • Logo
      • Message
      • Modal
      • Nav
      • Notification
      • Progress Bar
      • Search
      • Separator
      • Social
      • Stat
      • View
    • Push Notifications
    • Payments
    • Building Your App
  • Mission Control
    • Introduction
    • Installation
    • User Management
    • Feedback
    • Events
    • Logs
  • Website Template
    • Introduction
    • Environment Variables
    • Styling
    • Components
      • Article
      • Feature List
      • Footer
      • Hero
      • Layout
      • Pricing
      • Meta Data
      • Nav
      • Testimonial
    • Build and Deploy
Powered by GitBook
On this page
  • Sending Notifications to Yourself
  • Using Other Mail Providers
  • Using Custom Email Templates
  • Notification Preferences

Was this helpful?

  1. Gravity Server

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.

Sending Notifications to Yourself

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'
}

Using Other Mail Providers

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. Change the require import on line 7 of helper/mail to import your package

  2. 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
  }))
}

Using Custom Email Templates

Gravity includes a clean, responsive email template, but you can also add your own templates to cover a wider variety of use cases.

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

Notification Preferences

Users can't toggle which email notifications they would like to receive in the notifications section of their account.

These settings are stored in the database notifications table. By default, the following preferences are included for you:

  • new_signin

  • plan_updated

  • card_updated

  • invite_accepted

PreviousPush NotificationsNextUser Feedback

Last updated 1 year ago

Was this helpful?

This will send an email to the address stored in SUPPORT_EMAIL . You can see an example of this in the /help view.

Gravity uses with the default mail service set to .

Find and install the transport package from

A f

I recommend using 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, .

If you'd like to add more options you, add them to the notifications object in . This way, all new users will automatically have the these preferences added to the database.

environment variable
nodemailer
Mailgun
npm
ull list of well-known services is available here.
htmlemail.io
please follow the instructions in this blog post
config