const nodemailer = require('nodemailer'); const { SESv2Client, SendEmailCommand } = require('@aws-sdk/client-sesv2'); const sesClient = new SESv2Client({ region: process.env.AWS_REGION, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, }, }); // Create the transporter const transporter = nodemailer.createTransport({ SES: { sesClient, SendEmailCommand }, }); // Helper function to get color based on time of day function getColorForTime() { const hour = new Date().getHours(); if (hour >= 5 && hour < 10) { // Morning - orange return { primary: '#FF9800', gradient: 'linear-gradient(135deg, #FF9800 0%, #F57C00 100%)', shadow: 'rgba(255, 152, 0, 0.3)' }; } else if (hour >= 10 && hour < 18) { // Afternoon - blue return { primary: '#2196F3', gradient: 'linear-gradient(135deg, #2196F3 0%, #005CA8 100%)', shadow: 'rgba(33, 150, 243, 0.3)' }; } else { // Evening/Night - purple return { primary: '#471189', gradient: 'linear-gradient(135deg, #BA82FF 0%, #280059 100%)', shadow: 'rgba(71, 17, 137, 0.3)' }; } } // Helper function to send email async function sendVerificationEmail(toEmail, token, name) { const colors = getColorForTime(); const verificationLink = `https://wahwa.com/verify-email?token=${token}`; try { const info = await transporter.sendMail({ from: `"BlindMaster" <${process.env.EMAIL_FROM}>`, // Sender address to: toEmail, subject: "Verify your BlindMaster account", html: `

BlindMaster

Smart Home Automation

Welcome${name && name.trim() ? `, ${name.trim()}` : ''}!

Thank you for joining BlindMaster! To electrify your blinds, please verify your email address 🥹

Verify Email Address

This verification link will expire in 24 hours.

If you didn't create a BlindMaster account, please ignore this email!!!

© 2026 BlindMaster. All rights reserved.

`, }); console.log("Email sent successfully:", info.messageId); return true; } catch (error) { console.error("Error sending email:", error); return false; } } // Helper function to send password reset email async function sendPasswordResetEmail(toEmail, code, name) { const colors = getColorForTime(); try { const info = await transporter.sendMail({ from: `"BlindMaster" <${process.env.EMAIL_FROM}>`, to: toEmail, subject: "Reset your BlindMaster password", html: `

BlindMaster

Smart Home Automation

Password Reset Request

${name && name.trim() ? `Hi ${name.trim()}, we` : 'We'} received a request to reset your password. Use the code below to continue:

${code}

This code will expire in 15 minutes.

If you didn't request a password reset, please ignore this email.

© 2026 BlindMaster. All rights reserved.

`, }); console.log("Password reset email sent successfully:", info.messageId); return true; } catch (error) { console.error("Error sending password reset email:", error); return false; } } module.exports = { sendVerificationEmail, sendPasswordResetEmail };