-
Notifications
You must be signed in to change notification settings - Fork 18
/
mail.js
30 lines (27 loc) · 969 Bytes
/
mail.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
/* eslint no-console: 0*/
'use strict';
const nodemailer = require('nodemailer');
const nodemailerSendgrid = require('../index'); // require('nodemailer-sendgrid');
const transport = nodemailer.createTransport(
nodemailerSendgrid({
apiKey: process.env.SENDGRID_API_KEY
})
);
transport
.sendMail({
from: '[email protected]',
to: 'Andris Reinman <[email protected]>, [email protected]',
subject: 'hello world',
html: '<h1>Hello world!</h1>'
})
.then(([res]) => {
console.log('Message delivered with code %s %s', res.statusCode, res.statusMessage);
})
.catch(err => {
console.log('Errors occurred, failed to deliver message');
if (err.response && err.response.body && err.response.body.errors) {
err.response.body.errors.forEach(error => console.log('%s: %s', error.field, error.message));
} else {
console.log(err);
}
});