mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 16:23:23 +00:00
Add fromName field support to emails collection
- Add fromName field to Emails collection schema for sender display name - Update BaseEmailDocument and QueuedEmail interfaces to include fromName - Add SendEmailTaskInput support for fromName field in job tasks - Update MailingService to combine fromName and from into proper "Name <email>" format - Add fromName, from, and replyTo fields to job input schema for admin UI - Update field copying logic to handle new sender-related fields Users can now specify a display name for emails (e.g., "John Doe <john@example.com>"). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,13 @@ const Emails: CollectionConfig = {
|
||||
description: 'Sender email address (optional, uses default if not provided)',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'fromName',
|
||||
type: 'text',
|
||||
admin: {
|
||||
description: 'Sender display name (optional, e.g., "John Doe" for "John Doe <john@example.com>")',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'replyTo',
|
||||
type: 'text',
|
||||
|
||||
@@ -15,6 +15,9 @@ export interface SendEmailTaskInput {
|
||||
to: string | string[]
|
||||
cc?: string | string[]
|
||||
bcc?: string | string[]
|
||||
from?: string
|
||||
fromName?: string
|
||||
replyTo?: string
|
||||
scheduledAt?: string | Date // ISO date string or Date object
|
||||
priority?: number
|
||||
|
||||
@@ -39,7 +42,7 @@ function transformTaskInputToSendEmailOptions(taskInput: SendEmailTaskInput) {
|
||||
}
|
||||
|
||||
// Standard email fields that should be copied to data
|
||||
const standardFields = ['to', 'cc', 'bcc', 'subject', 'html', 'text', 'scheduledAt', 'priority']
|
||||
const standardFields = ['to', 'cc', 'bcc', 'from', 'fromName', 'replyTo', 'subject', 'html', 'text', 'scheduledAt', 'priority']
|
||||
|
||||
// Template-specific fields that should not be copied to data
|
||||
const templateFields = ['templateSlug', 'variables']
|
||||
@@ -135,6 +138,30 @@ export const sendEmailJob = {
|
||||
description: 'Optional comma-separated list of BCC email addresses'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'from',
|
||||
type: 'text' as const,
|
||||
label: 'From Email',
|
||||
admin: {
|
||||
description: 'Optional sender email address (uses default if not provided)'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'fromName',
|
||||
type: 'text' as const,
|
||||
label: 'From Name',
|
||||
admin: {
|
||||
description: 'Optional sender display name (e.g., "John Doe")'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'replyTo',
|
||||
type: 'text' as const,
|
||||
label: 'Reply To',
|
||||
admin: {
|
||||
description: 'Optional reply-to email address'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'scheduledAt',
|
||||
type: 'date' as const,
|
||||
|
||||
@@ -238,8 +238,16 @@ export class MailingService implements IMailingService {
|
||||
id: emailId,
|
||||
}) as BaseEmailDocument
|
||||
|
||||
// Combine from and fromName for nodemailer
|
||||
let fromField = email.from
|
||||
if (email.fromName && email.from) {
|
||||
fromField = `"${email.fromName}" <${email.from}>`
|
||||
} else if (email.from) {
|
||||
fromField = email.from
|
||||
}
|
||||
|
||||
const mailOptions = {
|
||||
from: email.from,
|
||||
from: fromField,
|
||||
to: email.to,
|
||||
cc: email.cc || undefined,
|
||||
bcc: email.bcc || undefined,
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface BaseEmailDocument {
|
||||
cc?: string[] | null
|
||||
bcc?: string[] | null
|
||||
from?: string | null
|
||||
fromName?: string | null
|
||||
replyTo?: string | null
|
||||
subject: string
|
||||
html: string
|
||||
@@ -83,6 +84,7 @@ export interface QueuedEmail {
|
||||
cc?: string[] | null
|
||||
bcc?: string[] | null
|
||||
from?: string | null
|
||||
fromName?: string | null
|
||||
replyTo?: string | null
|
||||
subject: string
|
||||
html: string
|
||||
|
||||
Reference in New Issue
Block a user