Fix turnstile
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import type { PayloadEmailAdapter, SendEmailOptions } from 'payload'
|
||||
|
||||
import { getSiteIntegrations } from '../payload/index.js'
|
||||
|
||||
/** SMTP fields the adapter reads from SiteIntegrations. */
|
||||
type SmtpIntegrations = {
|
||||
smtpFromAddress?: null | string
|
||||
smtpFromName?: null | string
|
||||
smtpHost?: null | string
|
||||
smtpPassword?: null | string
|
||||
smtpPort?: null | number
|
||||
smtpUser?: null | string
|
||||
smtpHost?: string | null
|
||||
smtpPort?: number | null
|
||||
smtpUser?: string | null
|
||||
smtpPassword?: string | null
|
||||
smtpFromAddress?: string | null
|
||||
smtpFromName?: string | null
|
||||
}
|
||||
|
||||
export type PanelSmtpAdapterArgs = {
|
||||
@@ -59,8 +58,10 @@ export const panelSmtpAdapter =
|
||||
const pass = smtp.smtpPassword
|
||||
|
||||
if (!host || !user || !pass) {
|
||||
payload.logger.error('[ipal] Email not sent: SMTP is not configured in Site Integrations.')
|
||||
return { error: 'SMTP is not configured in Site Integrations.', sent: false }
|
||||
payload.logger.error(
|
||||
'[ipal] Email not sent: SMTP is not configured in Site Integrations.',
|
||||
)
|
||||
return { sent: false, error: 'SMTP is not configured in Site Integrations.' }
|
||||
}
|
||||
|
||||
// The panel is the source of truth for the sender; fall back to whatever
|
||||
@@ -77,18 +78,15 @@ export const panelSmtpAdapter =
|
||||
// normalises CRLF in standard headers, but the form-builder interpolates
|
||||
// user data into the subject via {{field}} placeholders, so strip any
|
||||
// newlines from header-bound values before they reach the transport.
|
||||
const stripCRLF = (v: unknown): string =>
|
||||
String(v ?? '')
|
||||
.replace(/[\r\n]+/g, ' ')
|
||||
.trim()
|
||||
const stripCRLF = (v: unknown): string => String(v ?? '').replace(/[\r\n]+/g, ' ').trim()
|
||||
|
||||
const { default: nodemailer } = await import('nodemailer')
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
auth: { pass, user },
|
||||
host,
|
||||
port,
|
||||
secure: port === 465, // implicit TLS on 465, STARTTLS otherwise
|
||||
auth: { user, pass },
|
||||
})
|
||||
|
||||
try {
|
||||
@@ -97,12 +95,13 @@ export const panelSmtpAdapter =
|
||||
from,
|
||||
...(message.subject ? { subject: stripCRLF(message.subject) } : {}),
|
||||
})
|
||||
return { messageId: info.messageId, sent: true }
|
||||
return { sent: true, messageId: info.messageId }
|
||||
} catch (err) {
|
||||
// Never surface SMTP internals to the caller — a form submission
|
||||
// shouldn't fail loudly because the mailbox is misconfigured.
|
||||
payload.logger.error(`[ipal] Email send failed: ${(err as Error).message}`)
|
||||
return { error: 'Failed to send email.', sent: false }
|
||||
// `detail` is for the panel status (mailAdapter), not for end users.
|
||||
return { sent: false, error: 'Failed to send email.', detail: (err as Error).message }
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user