import nodemailer from "nodemailer"; //import juice from "juice"; // // Create reusable transporter object // export const mailer = nodemailer.createTransport({ host: "mail.metatron-admin-backend.metatronhost.com", // your Hestia mail host port: 587, // STARTTLS secure: false, // must be false for 587 auth: { user: "info@metatron-admin-backend.metatronhost.com", // e.g. info@metatron-admin-backend.metatronhost.com pass: "MetatronBackendAdmin@2025", // mailbox password }, name: "mail.metatron-admin-backend.metatronhost.com", // explicitly set hostname tls: { rejectUnauthorized: false, // allow self-signed certs }, logger: true, // optional: logs connection steps debug: true, // optional: debug SMTP connection }); // // Send welcome / signup email // export async function sendSignupMail(toEmail) { try { await mailer.sendMail({ from: `"CrawlerX" info@metatron-admin-backend.metatronhost.com`, to: toEmail, subject: "Welcome to CrawlerX", html: `

Welcome!

Your signup was successful. You can now log in and start using the app.

`, }); console.log(`✅ Signup email sent to ${toEmail}`); } catch (err) { console.error("❌ Error sending signup email:", err); } } // // Send reset-password email with 4-digit code or token link // export async function sendResetPasswordMail(email, token) { try { const resetURL = `${process.env.FRONTEND_URL}/reset-password?email=${email}&token=${token}`; await mailer.sendMail({ from: `"CrawlerX" <${process.env.SMTP_USER}>`, to: email, subject: "Reset your password", html: `

You requested a password reset.

Click here to reset: ${resetURL}

This link is valid for 1 hour.

`, }); console.log(`✅ Reset password email sent to ${email}`); } catch (err) { console.error("❌ Error sending reset password email:", err); } } export const sendCakeOrderMail = async (name, cemail, phone, email, order, totalPieces, totalPrice, hst) => { try { const transporter = nodemailer.createTransport({ host: "mail.metatron-admin-backend.metatronhost.com", port: 587, secure: false, auth: { user: "info@metatron-admin-backend.metatronhost.com", pass: "MetatronBackendAdmin@2025", }, tls: { rejectUnauthorized: false }, }); // ✅ Auto-calculate HST if not provided const hstAmount = hst && hst > 0 ? hst : totalPrice * 0.13; const grandTotal = totalPrice + hstAmount; // Build table rows let orderRows = ""; Object.entries(order).forEach(([category, items]) => { items.forEach(({ flavour, pieces, unitPrice, totalPrice: lineTotal }) => { orderRows += ` ${category} ${flavour} ${pieces} $${unitPrice.toFixed(2)} $${lineTotal.toFixed(2)} `; }); }); // ✅ New version: Show “HST (13%) included in total” const htmlContent = `
Order Date: ${new Date().toLocaleString()}

Order Details

Customer Details

Name: ${name}

Email: ${cemail}

Phone: ${phone}

${orderRows}
Treats Flavour Quantity Unit Price Total Price
Total Pieces ${totalPieces} Subtotal ($) $${totalPrice.toFixed(2)}
HST (13%) $${hstAmount.toFixed(2)}
Grand Total (includes 13% HST) $${grandTotal.toFixed(2)}

Note: Grand total includes 13% HST.

Visit Our Website
`; const mailOptions = { from: '"Maison de Treats" ', to: email, subject: "🎉 New Cake Order from Website Form", html: htmlContent, attachments: [ { filename: "logo-2.webp", path: "./public/maisondetreats/img/logo-2.webp", cid: "logo" }, { filename: "thank-you.png", path: "./public/maisondetreats/img/thank-you.png", cid: "banner" }, { filename: "bottom.png", path: "./public/maisondetreats/img/bottom.png", cid: "footer" }, ], }; await transporter.sendMail(mailOptions); console.log("✅ Cake order email sent to", email); } catch (err) { console.error("❌ Failed to send cake order email:", err); } };