-
Notifications
You must be signed in to change notification settings - Fork 1
/
optimizeEmailCode
55 lines (49 loc) · 2.08 KB
/
optimizeEmailCode
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
var nodemailer = require("nodemailer"); // package.json-- "nodemailer": "^6.4.2",
var emailConfig = require('../config/email')
const sendEmail = (subject, messageBody, mailTo) =>{
// create reusable transporter object using the default SMTP transport
const mailOptions = {
from: emailConfig.from, // sender address
to: mailTo, // list of receivers
subject: subject, // Subject line
html: messageBody// html body
};
let transporter = nodemailer.createTransport({
host: emailConfig.host,
port: emailConfig.port,
secure: emailConfig.secure, // true for 465, false for other ports
debug: emailConfig.debug,
auth: {
user: emailConfig.auth.user, //process.env.GMAIL_USER, // generated ethereal user
pass: emailConfig.auth.pass //process.env.GMAIL_PASSWORD // generated ethereal password
},
tls: {
rejectUnauthorized: emailConfig.tls.rejectUnauthorized
}
});
let response;
// send mail with defined transport object
transporter.sendMail(mailOptions).then(result => { // await
console.log('Email send successfull sent: %s', result);
response = { EmailSend: true, msg: "Successfully send email " };
}).catch(err => {
console.log('Error while sending email : %s', err);
response = { EmailSend: false, msg: "Fail to send e-mail " + err };
})
return response;
}
exports.sendEmail = sendEmail;
--------------------------------------------------------------
var sendEmailToUserForgerPassword = (data) => { // async
let messageBody = 'Hi ' + data.Name + ','
+ '<br><br>Your password for Shyam Parivar is: ' + cryptr.decrypt(data.Password)
+ '<br><br>Shyam Mobile Palace'
+ '<br>Shop no. 47, Hisar Road, Bhattu Mandi'
+ '<br>Fatehabad, Haryana 125053'
+ '<br>Mobile Number: +91 - 9254622222 + 91 - 9017822222'
+ '<br>Email: [email protected]';
const subject = 'Password request';
const mailTo = data.Email;
let response = sendEmail(subject, messageBody, mailTo);
return response;
}