-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (42 loc) · 1.4 KB
/
index.js
File metadata and controls
51 lines (42 loc) · 1.4 KB
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
import nodemailer from "nodemailer";
import dotenv from "dotenv";
import realine from "readline";
dotenv.config();
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
host: "email-smtp.ap-south-1.amazonaws.com",
port: 587,
secure: false, // true for port 465, false for other ports
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
});
const rl = realine.createInterface({
input: process.stdin,
output: process.stdout,
});
function askQuestion(query) {
return new Promise((resolve) => {
rl.question(query, (answer) => {
resolve(answer);
});
});
}
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// send mail with defined transport object
const subject = await askQuestion("Enter the subject of the mail: ");
const text = await askQuestion("Enter the text of the mail: ");
const info = await transporter.sendMail({
from: `"Ritik" <${process.env.SENDER_EMAIL}> `, // sender address
to: process.env.RECEIVER_EMAIL, // list of receivers
subject: subject, // Subject line
text: text, // plain text body
// html: "<b>Hello world?</b>", // html body
});
rl.close();
console.log("Message sent: %s", info.messageId);
// Message sent: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>
}
main().catch(console.error);