// ============================================================ // email.js — Send emails via Gmail using Nodemailer // ============================================================ const nodemailer = require('nodemailer'); const transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: process.env.EMAIL_USER, pass: process.env.EMAIL_PASS, }, }); // Send the OTP email to the user async function sendOTPEmail(toEmail, username, otp) { const mailOptions = { from: `"Auth System" <${process.env.EMAIL_USER}>`, to: toEmail, subject: 'Your OTP Code', html: `
Hello ${username},
Your login OTP code is:
This code expires in 5 minutes.
If you did not request this, please ignore this email.
Hello ${username},
You requested to change your password. Click the secure link below to set a new password:
This link expires in 15 minutes.
If you did not request this, please ignore this email and your password will remain unchanged.
Hello ${username},
We detected a new login to your account from a device we haven't seen before:
| Device | ${deviceInfo} |
| IP Address | ${ipAddress} |
| Time | ${timeStr} |
If this was you, no action is needed.
If you don't recognize this login, please change your password immediately
and log out of all devices from your dashboard.