website uses smtp

This commit is contained in:
2025-12-18 21:08:04 +00:00
parent ba4b4ea980
commit 64f2092161
3 changed files with 38 additions and 10 deletions

View File

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

View File

@@ -1,9 +1,14 @@
import crypto from "node:crypto"; import crypto from "node:crypto";
import { SENDMAIL_BIN } from "astro:env/server";
import nodemailer from "nodemailer"; 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 {
SMTP_HOST,
SMTP_PASSWORD,
SMTP_PORT,
SMTP_USER,
} from "astro:env/server";
export default defineAction({ export default defineAction({
input: z.object({ input: z.object({
@@ -46,6 +51,13 @@ to do anything.`,
} }
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport({
sendmail: true, host: SMTP_HOST,
path: SENDMAIL_BIN, port: SMTP_PORT,
secure: false,
authMethod: "PLAIN",
auth: {
type: "login",
user: SMTP_USER,
pass: SMTP_PASSWORD,
},
}); });

View File

@@ -1,9 +1,15 @@
import { z } from "astro/zod"; import { z } from "astro/zod";
import { actions, defineAction } from "astro:actions"; import { defineAction } from "astro:actions";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import { MAX_DAILY_EMAILS, SENDMAIL_BIN } from "astro:env/server"; import {
import { and, db, eq, gte, lte, SendmailToken, SentEmails } from "astro:db"; MAX_DAILY_EMAILS,
import { isToken } from "typescript"; SMTP_HOST,
SMTP_PASSWORD,
SMTP_PORT,
SMTP_USE_TLS,
SMTP_USER,
} from "astro:env/server";
import { and, db, eq, gte, SendmailToken, SentEmails } from "astro:db";
export default defineAction({ export default defineAction({
input: z.object({ input: z.object({
@@ -73,6 +79,13 @@ async function sendmail({
} }
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport({
sendmail: true, host: SMTP_HOST,
path: SENDMAIL_BIN, port: SMTP_PORT,
secure: false,
authMethod: "PLAIN",
auth: {
type: "login",
user: SMTP_USER,
pass: SMTP_PASSWORD,
},
}); });