A simple wrapper for nodemailer and SendGrid
require('dotenv').config()
const { SENDGRID_KEY, SENDGRID_FROM } = process.env
const Mail = require('@_727021/easymail')('templates', SENDGRID_FROM, SENDGRID_KEY)
const message = new Mail(
'to@example.com',
'Subject',
{
msg: 'This is an example email.'
},
'template.ejs'
)
message.send((err, html) => {
if (err) return console.error(err)
console.log('Email Sent!')
})
message.send()
.then(html => {
console.log('Email Sent!')
})
.catch(err => console.error(err))
;(async () => {
try {
const html = await message.send()
console.log('Email Sent!')
} catch (err) {
console.error(err)
}
})()