mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 16:23:23 +00:00
Add beforeSend hook for email customization
- Add BeforeSendHook type and BeforeSendMailOptions interface - Implement hook execution in MailingService before sending emails - Hook allows adding attachments, headers, and modifying email options - Add comprehensive documentation with examples - Bump version to 0.1.20
This commit is contained in:
@@ -270,7 +270,7 @@ export class MailingService implements IMailingService {
|
||||
fromField = this.getDefaultFrom()
|
||||
}
|
||||
|
||||
const mailOptions = {
|
||||
let mailOptions: any = {
|
||||
from: fromField,
|
||||
to: email.to,
|
||||
cc: email.cc || undefined,
|
||||
@@ -281,6 +281,16 @@ export class MailingService implements IMailingService {
|
||||
text: email.text || undefined,
|
||||
}
|
||||
|
||||
// Call beforeSend hook if configured
|
||||
if (this.config.beforeSend) {
|
||||
try {
|
||||
mailOptions = await this.config.beforeSend(mailOptions, email)
|
||||
} catch (error) {
|
||||
console.error('Error in beforeSend hook:', error)
|
||||
throw new Error(`beforeSend hook failed: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
||||
}
|
||||
}
|
||||
|
||||
await this.transporter.sendMail(mailOptions)
|
||||
|
||||
await this.payload.update({
|
||||
|
||||
Reference in New Issue
Block a user