fixes SMTP client config in website

This commit is contained in:
2026-01-08 21:13:38 +00:00
parent bde6f2a253
commit 48ca4c2a03
3 changed files with 28 additions and 36 deletions

View File

@@ -16,10 +16,18 @@ export default defineConfig({
context: "server", context: "server",
access: "secret", access: "secret",
}), }),
SMTP_HOST: envField.string({ context: "server", access: "secret" }), LOCAL_SMTP_ENVELOPE_FROM: envField.string({
SMTP_PORT: envField.number({ context: "server", access: "secret" }), context: "server",
SMTP_USER: envField.string({ context: "server", access: "secret" }), access: "secret",
SMTP_PASSWORD: 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", site: "https://joeac.net",

View File

@@ -1,14 +1,8 @@
import crypto from "node:crypto"; import crypto from "node:crypto";
import nodemailer from "nodemailer";
import { z } from "astro/zod"; import { z } from "astro/zod";
import { defineAction } from "astro:actions"; import { defineAction } from "astro:actions";
import { db, Otp } from "astro:db"; import { db, Otp } from "astro:db";
import { import { transporter } from "../sendmail";
SMTP_HOST,
SMTP_PASSWORD,
SMTP_PORT,
SMTP_USER,
} from "astro:env/server";
export default defineAction({ export default defineAction({
input: z.object({ input: z.object({
@@ -49,15 +43,3 @@ to do anything.`,
validUntil: Date.now() + 1000 * 60 * 5, 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,
},
});

View File

@@ -3,11 +3,12 @@ import { defineAction } from "astro:actions";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import { import {
MAX_DAILY_EMAILS, MAX_DAILY_EMAILS,
SMTP_HOST, LOCAL_SMTP_HOST,
SMTP_PASSWORD, LOCAL_SMTP_PASSWORD,
SMTP_PORT, LOCAL_SMTP_PORT,
SMTP_USE_TLS, LOCAL_SMTP_USER,
SMTP_USER, CONTACT_MAILBOX,
LOCAL_SMTP_ENVELOPE_FROM,
} from "astro:env/server"; } from "astro:env/server";
import { and, db, eq, gte, SendmailToken, SentEmails } from "astro:db"; import { and, db, eq, gte, SendmailToken, SentEmails } from "astro:db";
@@ -66,9 +67,9 @@ async function sendmail({
} }
const info = await transporter.sendMail({ const info = await transporter.sendMail({
from: `"Joe Carstairs" <me@joeac.net>`, from: LOCAL_SMTP_ENVELOPE_FROM,
to: `"Joe Carstairs" <me@joeac.net>`, to: CONTACT_MAILBOX,
subject: "joeac.net: a visitor left a message", subject: `joeac.net: ${name} left a message`,
text: `${name} <${email}> sent you a message:\n\n\n${message}`, text: `${name} <${email}> sent you a message:\n\n\n${message}`,
}); });
await db await db
@@ -78,14 +79,15 @@ async function sendmail({
console.log("Sent an email to Joe. Message ID: ", info.messageId); console.log("Sent an email to Joe. Message ID: ", info.messageId);
} }
const transporter = nodemailer.createTransport({ export const transporter = nodemailer.createTransport({
host: SMTP_HOST, host: LOCAL_SMTP_HOST,
port: SMTP_PORT, from: LOCAL_SMTP_ENVELOPE_FROM,
port: LOCAL_SMTP_PORT,
secure: false, secure: false,
authMethod: "PLAIN", authMethod: "PLAIN",
auth: { auth: {
type: "login", type: "login",
user: SMTP_USER, user: LOCAL_SMTP_USER,
pass: SMTP_PASSWORD, pass: LOCAL_SMTP_PASSWORD,
}, },
}); });