-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathsend_grid.js
40 lines (32 loc) · 1.09 KB
/
send_grid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Created by Zeeshan on 10/25/2016.
* Last updated March 20th, 2018
*/
//------------------------------------------------------
//sendgrid to send emails
//Web Link=> https://sendgrid.com/
//Run : node send_grid.js
//------------------------------------------------------
const nodemailer = require('nodemailer');
const sgTransport = require('nodemailer-sendgrid-transport');
const SENDGRID_APIKEY = 'API_KEY_HERE';
const sgOptions = {
auth: {
api_key: SENDGRID_APIKEY
}
};
const transporter = nodemailer.createTransport(sgTransport(sgOptions));
const subject = 'Hello Developer!';
const from = 'Node-Cheat <[email protected]>';
// TODO: come up with all set ready to use utility
const _sendMail = async (options) => {
const mailOptions = {
from: options.from || from,
to: options.to,
subject: options.subject || subject,
html: options.template,
};
console.log('sending mail');
await transporter.sendMail(mailOptions);
}
_sendMail({to: '[email protected]',template: '<strong>I am sent from Node-Cheat using sendgrid :)</strong>'});