Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(email-nodemailer): add email recipient override config #10050

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/email-nodemailer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import { InvalidConfiguration } from 'payload'
export type NodemailerAdapterArgs = {
defaultFromAddress: string
defaultFromName: string
/**
* Override all emails to be sent to this address.
* Useful for testing.
*/
overrideRecipientAddress?: string
/**
* Skip verifying the email SMTP transport.
*/
skipVerify?: boolean
transport?: Transporter
transportOptions?: SMTPConnection.Options
Expand All @@ -25,6 +33,7 @@ export const nodemailerAdapter = async (
args?: NodemailerAdapterArgs,
): Promise<NodemailerAdapter> => {
const { defaultFromAddress, defaultFromName, transport } = await buildEmail(args)
const overrideRecipientAddress = args?.overrideRecipientAddress

const adapter: NodemailerAdapter = () => ({
name: 'nodemailer',
Expand All @@ -34,6 +43,7 @@ export const nodemailerAdapter = async (
return await transport.sendMail({
from: `${defaultFromName} <${defaultFromAddress}>`,
...message,
...(overrideRecipientAddress ? { to: overrideRecipientAddress } : {}),
})
},
})
Expand Down
12 changes: 11 additions & 1 deletion packages/email-resend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export type ResendAdapterArgs = {
apiKey: string
defaultFromAddress: string
defaultFromName: string
/**
* Override all emails to be sent to this address.
* Useful for testing.
*/
overrideRecipientAddress?: string
}

type ResendAdapter = EmailAdapter<ResendResponse>
Expand All @@ -29,9 +34,14 @@ export const resendAdapter = (args: ResendAdapterArgs): ResendAdapter => {
defaultFromAddress,
defaultFromName,
sendEmail: async (message) => {
const modifiedMessage = {
...message,
...(args.overrideRecipientAddress ? { to: args.overrideRecipientAddress } : {}),
}

// Map the Payload email options to Resend email options
const sendEmailOptions = mapPayloadEmailToResendEmail(
message,
modifiedMessage,
defaultFromAddress,
defaultFromName,
)
Expand Down
Loading