whatever...
This commit is contained in:
+24
-15
@@ -1,14 +1,16 @@
|
|||||||
import nodemailer from 'nodemailer'
|
import nodemailer from 'nodemailer'
|
||||||
|
|
||||||
const transporter = nodemailer.createTransport({
|
function getTransporter() {
|
||||||
host: process.env.SMTP_HOST ?? 'mailpit',
|
return nodemailer.createTransport({
|
||||||
port: parseInt(process.env.SMTP_PORT ?? '1025'),
|
host: process.env.SMTP_HOST ?? 'localhost',
|
||||||
secure: process.env.SMTP_PORT === '465',
|
port: parseInt(process.env.SMTP_PORT ?? '1025'),
|
||||||
auth:
|
secure: process.env.SMTP_PORT === '465',
|
||||||
process.env.SMTP_USER
|
auth:
|
||||||
? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
|
process.env.SMTP_USER
|
||||||
: undefined,
|
? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
|
||||||
})
|
: undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function sendEmail({
|
export async function sendEmail({
|
||||||
to,
|
to,
|
||||||
@@ -19,10 +21,17 @@ export async function sendEmail({
|
|||||||
subject: string
|
subject: string
|
||||||
html: string
|
html: string
|
||||||
}) {
|
}) {
|
||||||
await transporter.sendMail({
|
console.log(`[email] Sending to ${to} via ${process.env.SMTP_HOST}:${process.env.SMTP_PORT}`)
|
||||||
from: `MulliganMates <${process.env.SMTP_FROM ?? 'noreply@golf.gy.gl'}>`,
|
try {
|
||||||
to,
|
const info = await getTransporter().sendMail({
|
||||||
subject,
|
from: `MulliganMates <${process.env.SMTP_FROM ?? 'noreply@golf.gy.gl'}>`,
|
||||||
html,
|
to,
|
||||||
})
|
subject,
|
||||||
|
html,
|
||||||
|
})
|
||||||
|
console.log('[email] Sent:', info.messageId)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[email] Failed:', err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user