diff --git a/website/astro.config.mjs b/website/astro.config.mjs index 6666f9a..0e56173 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -16,10 +16,18 @@ export default defineConfig({ context: "server", access: "secret", }), - SMTP_HOST: envField.string({ context: "server", access: "secret" }), - SMTP_PORT: envField.number({ context: "server", access: "secret" }), - SMTP_USER: envField.string({ context: "server", access: "secret" }), - SMTP_PASSWORD: envField.string({ context: "server", access: "secret" }), + LOCAL_SMTP_ENVELOPE_FROM: envField.string({ + context: "server", + access: "secret", + }), + LOCAL_SMTP_HOST: envField.string({ context: "server", access: "secret" }), + LOCAL_SMTP_PORT: envField.number({ context: "server", access: "secret" }), + LOCAL_SMTP_USER: envField.string({ context: "server", access: "secret" }), + LOCAL_SMTP_PASSWORD: envField.string({ + context: "server", + access: "secret", + }), + CONTACT_MAILBOX: envField.string({ context: "server", access: "secret" }), }, }, site: "https://joeac.net", diff --git a/website/src/actions/otp/send-otp.ts b/website/src/actions/otp/send-otp.ts index 23f8dc0..6f017af 100644 --- a/website/src/actions/otp/send-otp.ts +++ b/website/src/actions/otp/send-otp.ts @@ -1,14 +1,8 @@ import crypto from "node:crypto"; -import nodemailer from "nodemailer"; import { z } from "astro/zod"; import { defineAction } from "astro:actions"; import { db, Otp } from "astro:db"; -import { - SMTP_HOST, - SMTP_PASSWORD, - SMTP_PORT, - SMTP_USER, -} from "astro:env/server"; +import { transporter } from "../sendmail"; export default defineAction({ input: z.object({ @@ -49,15 +43,3 @@ to do anything.`, validUntil: Date.now() + 1000 * 60 * 5, }); } - -const transporter = nodemailer.createTransport({ - host: SMTP_HOST, - port: SMTP_PORT, - secure: false, - authMethod: "PLAIN", - auth: { - type: "login", - user: SMTP_USER, - pass: SMTP_PASSWORD, - }, -}); diff --git a/website/src/actions/sendmail.ts b/website/src/actions/sendmail.ts index bb7d2eb..d68ec95 100644 --- a/website/src/actions/sendmail.ts +++ b/website/src/actions/sendmail.ts @@ -3,11 +3,12 @@ import { defineAction } from "astro:actions"; import nodemailer from "nodemailer"; import { MAX_DAILY_EMAILS, - SMTP_HOST, - SMTP_PASSWORD, - SMTP_PORT, - SMTP_USE_TLS, - SMTP_USER, + LOCAL_SMTP_HOST, + LOCAL_SMTP_PASSWORD, + LOCAL_SMTP_PORT, + LOCAL_SMTP_USER, + CONTACT_MAILBOX, + LOCAL_SMTP_ENVELOPE_FROM, } from "astro:env/server"; import { and, db, eq, gte, SendmailToken, SentEmails } from "astro:db"; @@ -66,9 +67,9 @@ async function sendmail({ } const info = await transporter.sendMail({ - from: `"Joe Carstairs" `, - to: `"Joe Carstairs" `, - subject: "joeac.net: a visitor left a message", + from: LOCAL_SMTP_ENVELOPE_FROM, + to: CONTACT_MAILBOX, + subject: `joeac.net: ${name} left a message`, text: `${name} <${email}> sent you a message:\n\n\n${message}`, }); await db @@ -78,14 +79,15 @@ async function sendmail({ console.log("Sent an email to Joe. Message ID: ", info.messageId); } -const transporter = nodemailer.createTransport({ - host: SMTP_HOST, - port: SMTP_PORT, +export const transporter = nodemailer.createTransport({ + host: LOCAL_SMTP_HOST, + from: LOCAL_SMTP_ENVELOPE_FROM, + port: LOCAL_SMTP_PORT, secure: false, authMethod: "PLAIN", auth: { type: "login", - user: SMTP_USER, - pass: SMTP_PASSWORD, + user: LOCAL_SMTP_USER, + pass: LOCAL_SMTP_PASSWORD, }, });