mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 16:23:23 +00:00
Merge pull request #14 from xtr-dev/dev
Add defaultFromName config option and bump to v0.0.7
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-mailing",
|
"name": "@xtr-dev/payload-mailing",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"description": "Template-based email system with scheduling and job processing for PayloadCMS",
|
"description": "Template-based email system with scheduling and job processing for PayloadCMS",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -48,6 +48,20 @@ export class MailingService implements IMailingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getDefaultFrom(): string {
|
||||||
|
const fromEmail = this.config.defaultFrom
|
||||||
|
const fromName = this.config.defaultFromName
|
||||||
|
|
||||||
|
// Check if fromName exists, is not empty after trimming, and fromEmail exists
|
||||||
|
if (fromName && fromName.trim() && fromEmail) {
|
||||||
|
// Escape quotes in the display name to prevent malformed headers
|
||||||
|
const escapedName = fromName.replace(/"/g, '\\"')
|
||||||
|
return `"${escapedName}" <${fromEmail}>`
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromEmail || ''
|
||||||
|
}
|
||||||
|
|
||||||
private registerHandlebarsHelpers(): void {
|
private registerHandlebarsHelpers(): void {
|
||||||
Handlebars.registerHelper('formatDate', (date: Date, format?: string) => {
|
Handlebars.registerHelper('formatDate', (date: Date, format?: string) => {
|
||||||
if (!date) return ''
|
if (!date) return ''
|
||||||
@@ -128,7 +142,7 @@ export class MailingService implements IMailingService {
|
|||||||
to: Array.isArray(options.to) ? options.to : [options.to],
|
to: Array.isArray(options.to) ? options.to : [options.to],
|
||||||
cc: options.cc ? (Array.isArray(options.cc) ? options.cc : [options.cc]) : undefined,
|
cc: options.cc ? (Array.isArray(options.cc) ? options.cc : [options.cc]) : undefined,
|
||||||
bcc: options.bcc ? (Array.isArray(options.bcc) ? options.bcc : [options.bcc]) : undefined,
|
bcc: options.bcc ? (Array.isArray(options.bcc) ? options.bcc : [options.bcc]) : undefined,
|
||||||
from: options.from || this.config.defaultFrom,
|
from: options.from || this.getDefaultFrom(),
|
||||||
replyTo: options.replyTo,
|
replyTo: options.replyTo,
|
||||||
subject: subject || options.subject,
|
subject: subject || options.subject,
|
||||||
html,
|
html,
|
||||||
@@ -245,7 +259,7 @@ export class MailingService implements IMailingService {
|
|||||||
}) as QueuedEmail
|
}) as QueuedEmail
|
||||||
|
|
||||||
let emailObject: EmailObject = {
|
let emailObject: EmailObject = {
|
||||||
from: email.from || this.config.defaultFrom,
|
from: email.from || this.getDefaultFrom(),
|
||||||
to: email.to,
|
to: email.to,
|
||||||
cc: email.cc || undefined,
|
cc: email.cc || undefined,
|
||||||
bcc: email.bcc || undefined,
|
bcc: email.bcc || undefined,
|
||||||
@@ -262,7 +276,7 @@ export class MailingService implements IMailingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
from: emailObject.from || this.config.defaultFrom,
|
from: emailObject.from,
|
||||||
to: emailObject.to,
|
to: emailObject.to,
|
||||||
cc: emailObject.cc || undefined,
|
cc: emailObject.cc || undefined,
|
||||||
bcc: emailObject.bcc || undefined,
|
bcc: emailObject.bcc || undefined,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export interface MailingPluginConfig {
|
|||||||
emails?: string | Partial<CollectionConfig>
|
emails?: string | Partial<CollectionConfig>
|
||||||
}
|
}
|
||||||
defaultFrom?: string
|
defaultFrom?: string
|
||||||
|
defaultFromName?: string
|
||||||
transport?: Transporter | MailingTransportConfig
|
transport?: Transporter | MailingTransportConfig
|
||||||
queue?: string
|
queue?: string
|
||||||
retryAttempts?: number
|
retryAttempts?: number
|
||||||
|
|||||||
Reference in New Issue
Block a user