sendjml
v0.8.2
Published
Send emails using `mjml`.
Downloads
9
Readme
Sendjml
Send emails using mjml
.
Design templates
In order to have a design structure, is necessary to set the folder containing the .mjml
files.
{
...config,
templates: `${__dirname}/design`,
}
The library will search for design templates, and overrides at the send time, always in this folder.
Using Sendgrid
We use Sendgrid mail library in case you have an API key already created.
yarn add sendjml @sendgrid/mail
Config using Sendgrid
const { sendgrid } = require('sendjml')
sendgrid.config({
apiKey: process.env.SG_API_KEY,
from: '[email protected]',
templates: `${__dirname}/design`,
})
Send using Sendgrid
const { sendgrid } = require('sendjml')
await sendgrid.send({
to: '[email protected]',
subject: 'This is an email sent using Sendgrid',
text: 'Sendgrid Lorem ipsum',
})
Using Gmail
In order to send emails using Gmail as SMTP, we use nodemailer. Sending this way is necessary to create an OAuth keys in a Google Cloud Platform application following this guide as an example.
yarn add sendjml nodemailer googleapis
Config using Gmail
In this case, the from
field is not necessary because Gmail uses the one set as gmailUser
.
const { gmail } = require('sendjml')
gmail.config({
gmailUser: process.env.MAIL_USERNAME,
oauthClientId: process.env.OAUTH_CLIENTID,
oauthClientSecret: process.env.OAUTH_CLIENT_SECRET,
oauthRefreshToken: process.env.OAUTH_REFRESH_TOKEN,
})
Send using Gmail
const { gmail } = require('sendjml')
await gmail.send({
to: '[email protected]',
subject: 'This is an email sent using Sendgrid',
text: 'Sendgrid Lorem ipsum',
})