sendEmailNN.js
1.64 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
52
53
54
55
56
57
const APIKEY = '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'
let emailOption = {
"options": {
"auth": {
"api_key": APIKEY
}
},
"from": "no-reply@sourcecode.co.th",
"subject": "Test send mail",
"html": "./conf/emailTemplate.txt"
}
sendEmail = function (emailTo) {
const nodemailer = require('nodemailer');
const sendgridTransport = require('nodemailer-sendgrid-transport');
/* ----------------------------- constant value ----------------------------- */
const sendEmail = emailOption
// Create a SendGrid transporter using your API key-
const transporter = nodemailer.createTransport(
sendgridTransport(sendEmail.options)
// {
// host: 'smtp.office365.com',
// port: 587,
// secure: false, // TLS requires secureConnection to be false
// auth: {
// user: 'nattaponw@sourcecode.co.th',
// pass: 'Dkigiupo035'
// }
// }
);
// Email content
let html = '<b>Awesome sauce</b>'
// html = html.replace('$organizationName', orgName)
const mailOptions = {
from: 'sc.nattaponw@gmail.com', // Sender email address
to: emailTo, // Recipient email address (you can use an array for multiple recipients)
subject: 'test Subject', // Email subject
html: html
};
// Send the email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error('Error:', error);
} else {
console.log('Email sent:', info);
}
});
}
sendEmail('mil2inda@gmail.com')