forked from nodemailer/nodemailer-sendgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
36 lines (33 loc) · 934 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
31
32
33
34
35
36
/* eslint no-console: 0*/
"use strict";
const nodemailer = require("nodemailer");
const nodemailerSendgrid = require("../index"); // require('@newesissrl/nodemailer-sendgrid');
const transport = nodemailer.createTransport(
nodemailerSendgrid({
apiKey: process.env.SENDGRID_API_KEY,
})
);
transport
.sendMail({
from: "alberto@newesis.com",
to: "Rauno De Pasquale <rauno@newesis.com>",
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);
}
});