-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendEmail.js
More file actions
38 lines (33 loc) · 905 Bytes
/
sendEmail.js
File metadata and controls
38 lines (33 loc) · 905 Bytes
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
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'fakenitin9935@gmail.com',
pass: '9115275119'
}
});
function randomNumber() {
let num = 0;
while (num < 1000 || num > 9999) {
num = Math.floor((Math.random() * 10000) + 1000);
}
return num;
}
// Less secure app access myaccount.google.com/lesssecureapps
module.exports = function (userEmail) {
let num = randomNumber().toString();
// console.log(num);
let mailOptions = {
from: 'fakenitin9935@gmail.com',
to: userEmail,
subject: 'One time password',
text: num
};
transporter.sendMail(mailOptions, function (error, info) {
if (error)
console.log(error);
// else
// console.log('mail Sended: ' + info.response);
});
return num;
};