mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-08-22 16:47:16 -05:00
feat: fix mailer FROM header
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user