From 272eb607c83e567ff49afc4e992f559ea9c5e05e Mon Sep 17 00:00:00 2001 From: nmemmert Date: Wed, 6 May 2026 15:38:16 -0400 Subject: [PATCH] Add personalized newsletter welcome email flow --- server.js | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/server.js b/server.js index 3aa9195..7d4bcd2 100644 --- a/server.js +++ b/server.js @@ -421,6 +421,12 @@ function normalizeMessageType(value) { return 'general' } +const USE_RESEND_AUTOMATION_WELCOME = process.env.RESEND_AUTOMATION_WELCOME === 'true' + +function shouldSendWelcomeEmail({ subscribe }) { + return subscribe === true +} + function addContactSubmission({ name, email, message, messageType, subscribe }) { const submission = { id: randomUUID(), @@ -1829,6 +1835,9 @@ app.post('/api/contact', contactRateLimit, async (req, res) => { dateStyle: 'medium', timeStyle: 'short', }) + const shouldSendWelcome = shouldSendWelcomeEmail({ + subscribe, + }) addContactSubmission({ name: trimmedName, @@ -1866,6 +1875,97 @@ app.post('/api/contact', contactRateLimit, async (req, res) => { await syncContactToResend(trimmedName, trimmedEmail) } + if (shouldSendWelcome && !USE_RESEND_AUTOMATION_WELCOME) { + const greetingName = splitName(trimmedName).firstName?.trim() ?? '' + const welcomeHeading = greetingName + ? `Glad you’re here, ${escapeHtml(greetingName)}.` + : 'Glad you’re here.' + const welcomeSpotifyUrl = process.env.RESEND_WELCOME_SPOTIFY_URL ?? 'https://versebyversewithnate.us/spotify' + const welcomeAppleUrl = process.env.RESEND_WELCOME_APPLE_URL ?? 'https://versebyversewithnate.us/apple' + const welcomeAmazonUrl = process.env.RESEND_WELCOME_AMAZON_URL ?? 'https://versebyversewithnate.us/amazon' + const welcomeWebsiteUrl = process.env.RESEND_WELCOME_WEBSITE_URL ?? 'https://versebyversewithnate.us' + const welcomeEpisodeUrl = process.env.RESEND_WELCOME_EPISODE_URL ?? 'https://versebyversewithnate.us/start-here' + const welcomeImageUrl = process.env.RESEND_WELCOME_IMAGE_URL ?? 'https://versebyversewithnate.us/images/podcast-art.jpeg' + + const { error: welcomeError } = await resend.emails.send({ + from: process.env.RESEND_FROM ?? 'Verse by Verse with Nate ', + to: [trimmedEmail], + subject: process.env.RESEND_WELCOME_SUBJECT ?? 'Welcome to Verse by Verse with Nate', + text: + `Welcome to Verse by Verse with Nate!\n\n` + + `${greetingName ? `Glad you're here, ${greetingName}.` : "Glad you're here."}\n\n` + + `Start here: ${welcomeEpisodeUrl}\n` + + `Spotify: ${welcomeSpotifyUrl}\n` + + `Apple Podcasts: ${welcomeAppleUrl}\n` + + `Amazon Music: ${welcomeAmazonUrl}\n\n` + + `Grace and peace,\nNate`, + html: + `
` + + `` + + `
` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `
` + + `Verse by Verse with Nate` + + `

Verse by Verse with Nate

` + + `

Verse by verse. Nugget by nugget.

` + + `
` + + `

Welcome

` + + `

${welcomeHeading}

` + + `
` + + `
` + + `

Thanks for subscribing to Verse by Verse with Nate - a Bible teaching podcast where we slow down, dig into the text, and pull out the nuggets God has for us word by word.

` + + `

Right now we’re working through the book of Titus - a short letter packed with practical wisdom about grace, godliness, and what the Christian life looks like when it’s rooted in sound doctrine.

` + + `

If you’re just joining us, the best place to start is Episode 1. It sets the table for everything that follows.

` + + `
` + + `

Start here

` + + `

Episode 1 - Introduction to Titus

` + + `

Who wrote it, who received it, and why it still matters.

` + + `` + + `` + + `` + + `
Listen on SpotifyApple Podcasts
` + + `

Open Start Here page

` + + `
` + + `

What to expect

` + + `

Verse-by-verse teaching - we go slow and let the text speak for itself.

` + + `

Greek word studies - the kind that open up meaning without being a lecture.

` + + `

New episodes + study notes delivered right to your inbox.

` + + `
` + + `
` + + `

“For the grace of God has appeared, bringing salvation to all people.”

` + + `

Titus 2:11 - BSB

` + + `
` + + `
` + + `

Find the podcast on

` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `
Spotify·Apple Podcasts·Amazon Music·Website
` + + `

You’re receiving this because you subscribed to Verse by Verse with Nate.

` + + `

“Your word is a lamp to my feet and a light to my path.” - Psalm 119:105

` + + `
` + + `
` + + `
`, + }) + + if (welcomeError) throw welcomeError + } + const { error } = await resend.emails.send({ from: process.env.RESEND_FROM ?? 'Verse by Verse with Nate ', to: [process.env.RESEND_TO ?? 'hello@versebyversewithnate.us'],