-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-email.js
69 lines (58 loc) · 1.81 KB
/
test-email.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const nodemailer = require("nodemailer");
require("dotenv").config();
async function SendTestEmail() {
var mailConfig;
if (process.env.NODE_ENV === "production") {
// all emails are delivered to destination
mailConfig = {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
auth: {
user: process.env.SMTP_EMAIL,
pass: process.env.SMTP_PASSWORD,
},
};
var transporter = nodemailer.createTransport(mailConfig);
transporter
.sendMail({
from: process.env.SMTP_EMAIL, // sender address
to: "[email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
})
.then((info) => {
console.log("Email sent callback");
});
console.log(mailConfig);
} else {
// all emails are catched by ethereal.email
let testAccount = await nodemailer.createTestAccount();
mailConfig = {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass,
},
};
console.log(mailConfig);
var transporter = nodemailer.createTransport(mailConfig);
transporter
.sendMail({
from: '"Fred Foo 👻" <[email protected]>', // sender address
to: "[email protected], [email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
})
.then((info) => {
console.log("Preview URL: " + nodemailer.getTestMessageUrl(info));
});
console.log(mailConfig);
}
}
const start = async function(){
await SendTestEmail()
}
start()