Hello Community I am stuck at one point. I want to develop on functionality in this functionality when we call email send route it will also send the OTP.
I am developed two functions one is for email send and one is for nodemailer.
Email sent function
const emailSend = async (req,res)=>{
let data = await users.findOne({email: req.body.email})
const responseType = {};
if(data){
let otpCode = Math.floor((Math.random()*10000)+1);
let otpData = new otp({
email: req.body.email,
code: otpCode,
expiresIn: new Date().getTime() + 300*1000
})
let otpResponse = await otpData.save();
responseType.statusText = 'Success'
responseType.message = 'Please check your email id'
}
else{
responseType.statusText = 'Error'
responseType.message = 'Email id not exist'
}
res.status(200).json(responseType);
}
Nodemailer function
const mailer = () =>{
var transporter = nodemailer.createTransport({
service: 'gmail',
port: 587,
secureConnection: false,
auth: {
user: 'Your Email',
pass: 'Your Password'
}
});
var mailOptions = {
from: 'sender address',
to: 'list of receivers',
subject: 'Test',
text: "Hello",
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error.message);
}
console.log('Email Sent: '+ info);
});
}
When I hit email sent URL on Postman tool it will send the email but I want send email as well as OTP is also send.
Thanks in advance.