feat: fix mailer FROM header
Some checks failed
Build and Publish Docker Image / Build and Publish (amd64) (push) Has been cancelled
Build and Publish Docker Image / Build and Publish (arm64) (push) Has been cancelled

This commit is contained in:
mrjvs
2026-08-12 21:48:16 +02:00
parent 8612c4c647
commit a131700343
2 changed files with 31 additions and 12 deletions

View File

@@ -1,13 +1,13 @@
import { useMailer } from './mailer';
import { usePapr } from './papr';
import { assignDiscordMemberSupporterRole, assignDiscordMemberTesterRole, removeDiscordMemberSupporterRole, removeDiscordMemberTesterRole, useDiscord } from './discord';
import type { Transporter } from 'nodemailer';
import type { PaprMatchKeysAndValues } from 'papr';
import type { Stripe } from 'stripe';
import type { H3Event } from 'h3';
import type { Mailer } from './mailer';
import type { PnidDocument } from './papr';
async function sendEmailToCustomer(mailer: Transporter, customer: Stripe.Customer, ops: { pid: number; title: string; body: string }): Promise<void> {
async function sendEmailToCustomer(mailer: Mailer, customer: Stripe.Customer, ops: { pid: number; title: string; body: string }): Promise<void> {
try {
if (!customer.email) {
throw new Error('Customer does not have an email');
@@ -22,7 +22,7 @@ async function sendEmailToCustomer(mailer: Transporter, customer: Stripe.Custome
}
}
async function sendToNotificationEmails(mailer: Transporter, notificationEmails: string[], ops: { title: string; body: string }): Promise<void> {
async function sendToNotificationEmails(mailer: Mailer, notificationEmails: string[], ops: { title: string; body: string }): Promise<void> {
for (const email of notificationEmails) {
// * Send notification emails for new sub
try {

View File

@@ -1,18 +1,33 @@
import { createTransport } from 'nodemailer';
import type SMTPTransport from 'nodemailer/lib/smtp-transport';
import type Mail from 'nodemailer/lib/mailer';
import type { Transporter } from 'nodemailer';
import type { H3Event } from 'h3';
let transport: Transporter | null = null;
let mailer: Mailer | null = null;
export function useMailer(event: H3Event): Transporter | null {
if (!transport) {
export type Mailer = {
transport: Transporter<SMTPTransport.SentMessageInfo, SMTPTransport.Options>;
sendMail(ops: Mail.Options & Partial<SMTPTransport.Options>): Promise<SMTPTransport.SentMessageInfo>;
};
function buildMailer(transport: Transporter<SMTPTransport.SentMessageInfo, SMTPTransport.Options>, from: Mail.Address): Mailer {
return {
transport,
sendMail(ops) {
return transport.sendMail({
from,
...ops
});
}
};
}
export function useMailer(event: H3Event): Mailer | null {
if (!mailer) {
const config = useRuntimeConfig(event);
if (config.smtpHost && config.smtpPort && config.smtpFromEmail) {
transport = createTransport({
from: {
address: config.smtpFromEmail,
name: config.smtpFromName ? config.smtpFromName : undefined
},
const transport = createTransport({
host: config.smtpHost,
port: config.smtpPort,
secure: config.smtpSecure,
@@ -21,8 +36,12 @@ export function useMailer(event: H3Event): Transporter | null {
pass: config.smtpPassword ? config.smtpPassword : undefined
}
});
mailer = buildMailer(transport, {
address: config.smtpFromEmail,
name: config.smtpFromName ? config.smtpFromName : undefined
});
}
}
return transport;
return mailer;
}