Remove emailWrapper hook and all associated references.

- Simplified email sending logic by dropping custom layout wrapping.
- Updated service, config, types, and readme to remove `emailWrapper` usage.
- Retained focus on core email functionality while ensuring consistent formatting.
This commit is contained in:
2025-09-13 22:31:05 +02:00
parent 31721dc110
commit 2e6feccf54
5 changed files with 9 additions and 368 deletions

View File

@@ -8,7 +8,7 @@ import {
EmailTemplate,
QueuedEmail,
MailingTransportConfig,
EmailObject
BaseEmail
} from '../types/index.js'
import { serializeRichTextToHTML, serializeRichTextToText } from '../utils/richTextSerializer.js'
@@ -238,10 +238,10 @@ export class MailingService implements IMailingService {
const email = await this.payload.findByID({
collection: this.emailsCollection as any,
id: emailId,
}) as QueuedEmail
}) as BaseEmail
let emailObject: EmailObject = {
from: email.from || this.getDefaultFrom(),
const mailOptions = {
from: email.from,
to: email.to,
cc: email.cc || undefined,
bcc: email.bcc || undefined,
@@ -249,23 +249,6 @@ export class MailingService implements IMailingService {
subject: email.subject,
html: email.html,
text: email.text || undefined,
variables: email.variables,
}
// Apply emailWrapper hook if configured
if (this.config.emailWrapper) {
emailObject = await this.config.emailWrapper(emailObject)
}
const mailOptions = {
from: emailObject.from,
to: emailObject.to,
cc: emailObject.cc || undefined,
bcc: emailObject.bcc || undefined,
replyTo: emailObject.replyTo || undefined,
subject: emailObject.subject,
html: emailObject.html,
text: emailObject.text || undefined,
}
await this.transporter.sendMail(mailOptions)

View File

@@ -1,20 +1,9 @@
import { Payload } from 'payload'
import type { CollectionConfig, RichTextField, TypedCollection } from 'payload'
import type { CollectionConfig, RichTextField } from 'payload'
import { Transporter } from 'nodemailer'
import {Email} from "../payload-types.js"
export interface EmailObject {
to: string | string[]
cc?: string | string[]
bcc?: string | string[]
from?: string
replyTo?: string
subject: string
html: string
text?: string
variables?: Record<string, any>
}
export type EmailWrapperHook = (email: EmailObject) => EmailObject | Promise<EmailObject>
export type BaseEmail<TEmail = Email, TEmailTemplate = EmailTemplate> = Omit<TEmail, 'id' | 'template'> & {template: Omit<TEmailTemplate, 'id'>}
export type TemplateRendererHook = (template: string, variables: Record<string, any>) => string | Promise<string>
@@ -31,7 +20,6 @@ export interface MailingPluginConfig {
queue?: string
retryAttempts?: number
retryDelay?: number
emailWrapper?: EmailWrapperHook
templateRenderer?: TemplateRendererHook
templateEngine?: TemplateEngine
richTextEditor?: RichTextField['editor']