UNPKG

@express-knex/mailer

Version:

Express Knex project, mailer based on Sendgrid and Marked

20 lines (16 loc) 489 B
import sgMail from '@sendgrid/mail' import _ from 'lodash' import { markdown, plaintext } from './markdown' const msg = { from: 'noreply@goodcar.rent' } const mail = (to, subject, message) => sgMail.send(_.merge(msg, { to, subject, text: plaintext(message), html: markdown(message) })) export default (app) => { if (app.env.MAIL_API_KEY) { sgMail.setApiKey(process.env.MAIL_API_KEY) } else { throw Error('Expecting to have MAIL_API_KEY on app.env!') } return mail }