Switch contact email to Resend API, remove nodemailer/SMTP

This commit is contained in:
nmemmert
2026-04-09 14:40:19 -04:00
parent 4b01d01133
commit d95ed9cd8d
4 changed files with 98 additions and 55 deletions
+9 -23
View File
@@ -2,15 +2,7 @@ import express from 'express'
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import nodemailer from 'nodemailer'
function htmlEsc(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
}
import { Resend } from 'resend'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
@@ -97,27 +89,21 @@ app.post('/api/contact', contactRateLimit, async (req, res) => {
return
}
if (!process.env.SMTP_USER || !process.env.SMTP_PASS) {
console.error('[contact] SMTP_USER / SMTP_PASS env vars not set')
if (!process.env.RESEND_API_KEY) {
console.error('[contact] RESEND_API_KEY env var not set')
res.status(503).json({ message: 'The contact form is not yet configured on the server.' })
return
}
const transporter = nodemailer.createTransport({
host: 'smtp-mail.outlook.com',
port: 587,
secure: false,
auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS },
})
await transporter.sendMail({
from: process.env.SMTP_USER,
to: process.env.SMTP_USER,
replyTo: `"${name.trim()}" <${email.trim()}>`,
const resend = new Resend(process.env.RESEND_API_KEY)
const { error } = await resend.emails.send({
from: process.env.RESEND_FROM ?? 'Verse by Verse <onboarding@resend.dev>',
to: [process.env.RESEND_TO ?? 'vbvwithnate@outlook.com'],
reply_to: `${name.trim()} <${email.trim()}>`,
subject: `New message from Verse by Verse website — ${name.trim()}`,
text: `Name: ${name.trim()}\nEmail: ${email.trim()}\n\nMessage:\n${message.trim()}`,
html: `<p><strong>Name:</strong> ${htmlEsc(name.trim())}</p><p><strong>Email:</strong> ${htmlEsc(email.trim())}</p><hr/><pre style="font-family:sans-serif">${htmlEsc(message.trim())}</pre>`,
})
if (error) throw error
res.json({ ok: true })
} catch (err) {