diff --git a/src/routes/contact.js b/src/routes/contact.js index 738bcca..ea67543 100644 --- a/src/routes/contact.js +++ b/src/routes/contact.js @@ -1,7 +1,7 @@ import express from 'express'; import { dbRun, dbAll, dbGet } from '../db/database.js'; import { generateId, ApiResponse, asyncHandler } from '../utils/helpers.js'; -import { sendContactEmail } from '../services/email.js'; +import { sendContactEmail, sendAutoReply } from '../services/email.js'; const router = express.Router(); @@ -65,7 +65,7 @@ router.post('/', asyncHandler(async (req, res) => { console.log(`New contact submission: ${submissionId} from ${email}`); - // Send email notification (fire-and-forget — don't block the response) + // Send email notification to you (fire-and-forget) sendContactEmail({ name: name.trim(), email: email.trim().toLowerCase(), company: company?.trim(), message: message.trim() }) .then((result) => { if (result.success) { @@ -78,6 +78,19 @@ router.post('/', asyncHandler(async (req, res) => { console.error(`[Contact] Email error for submission ${submissionId}:`, err.message); }); + // Send auto-reply to the submitter (fire-and-forget) + sendAutoReply({ name: name.trim(), email: email.trim().toLowerCase() }) + .then((result) => { + if (result.success) { + console.log(`[Contact] Auto-reply sent for submission ${submissionId}`); + } else { + console.warn(`[Contact] Auto-reply failed for submission ${submissionId}: ${result.error}`); + } + }) + .catch((err) => { + console.error(`[Contact] Auto-reply error for submission ${submissionId}:`, err.message); + }); + res.status(201).json(ApiResponse(true, { id: submissionId, message: 'Thank you for your message! We\'ll get back to you soon.' diff --git a/src/services/email.js b/src/services/email.js index 9ef0156..c839e47 100644 --- a/src/services/email.js +++ b/src/services/email.js @@ -132,6 +132,84 @@ export const sendContactEmail = async ({ name, email, company, message }) => { } }; +/** + * Send an auto-reply thank-you email to the person who submitted the form. + * + * @param {Object} params + * @param {string} params.name - Submitter's name + * @param {string} params.email - Submitter's email + * @returns {Promise<{success: boolean, messageId?: string, error?: string}>} + */ +export const sendAutoReply = async ({ name, email }) => { + try { + const transporter = createTransport(); + const from = getFromAddress(); + + const info = await transporter.sendMail({ + from: `"Moxiegen" <${from}>`, + to: email, + subject: 'Thank you for contacting Moxiegen', + text: [ + `Dear ${name},`, + '', + 'Thank you for reaching out to Moxiegen. We have received your inquiry', + 'and our team is currently reviewing your message.', + '', + 'We understand the importance of your request and will make every effort', + 'to respond to you as promptly as possible. In most cases, you can expect', + 'to hear back from us within one business day.', + '', + 'If your matter is urgent, please feel free to call us directly at', + '+1 (855) 246-6943 or email info@moxiegen.com.', + '', + 'Thank you for your interest in Moxiegen. We look forward to speaking with you.', + '', + 'Best regards,', + 'The Moxiegen Team', + 'https://moxiegen.com', + ].join('\n'), + html: ` +
Algorithmic Enhancement for Enterprise AI
+Dear ${escapeHtml(name)},
++ Thank you for reaching out to Moxiegen. We have received your inquiry and our team is currently reviewing your message. +
++ We understand the importance of your request and will make every effort to respond to you as promptly as possible. In most cases, you can expect to hear back from us within one business day. +
+Need a faster response?
++ Call us at +1 (855) 246-6943 or email + info@moxiegen.com +
++ Thank you for your interest in Moxiegen. We look forward to speaking with you. +
+Best regards,
+The Moxiegen Team
+