-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
53 lines (47 loc) · 1.43 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
const nodemailer = require("nodemailer");
/**
* sendEmail
* @param {Object} mailObj - Email meta data and body
* @param {String} from - Email address of the sender
* @param {Array} receipents - Array of receipents email address
* @param {String} subject - Subject of the email
* @param {String} message - message
*/
const sendEmail = async (mailObj) => {
const { from, receipents, subject, message } = mailObj;
try {
// Create a transporter
let transporter = nodemailer.createTransport({
host: "smtp-relay.sendinblue.com",
port: 587,
auth: {
user: "[email protected]",
pass: "SMTP-KEY",
},
});
// send mail with defined transport object
let mailStatus = await transporter.sendMail({
from: from, // sender address
to: receipents, // list of receipents
subject: subject, // Subject line
text: message, // plain text
});
console.log(`Message sent: ${mailStatus.messageId}`);
return `Message sent: ${mailStatus.messageId}`;
} catch (error) {
console.error(error);
throw new Error(
`Something went wrong in the sendmail method. Error: ${error.message}`
);
}
};
const mailObj = {
from: "[email protected]",
receipents: ["[email protected]"],
subject: "Sending email by nodejs",
message: "Namaste",
};
sendEmail(mailObj).then((res) => {
console.log(res);
});