Skip to content

@payloadcms/email-resend — attachments are always corrupt (mapAttachments breaks both path and content) #16093

@gijzy

Description

@gijzy

Bug Report

The mapAttachments function in @payloadcms/email-resend has two bugs that make all email attachments arrive corrupt or fail entirely.

Bug 1: path is not supported

The docs recommend using path for cloud storage:

attachments: [{ filename: 'invoice.pdf', path: mediaDoc.url }]

But mapAttachments requires content to exist and throws if it's missing:

if (!attachment.filename || !attachment.content) {
  throw new APIError('Attachment is missing filename or content', 400);
}

The path property is defined in the Attachment type but never read or forwarded.

Bug 2: content as base64 string produces corrupt files

The docs also show passing base64 content:

attachments: [{ filename: 'invoice.pdf', content: fileBuffer.toString('base64') }]

But mapAttachments wraps the string in Buffer.from(attachment.content) (treating base64 as UTF-8 text). This Buffer is then serialized via JSON.stringify(), producing {"type":"Buffer","data":[83,71,...]} instead of the base64 string that the Resend REST API expects. The attachment arrives corrupt.

Suggested fix

mapAttachments should:

  1. Pass path through when content is absent
  2. Keep base64 strings as-is (don't wrap in Buffer) since JSON.stringify is used downstream

Reproduction

Any call to payload.sendEmail() with attachments using the Resend adapter.

Version: @payloadcms/email-resend@3.73.0 (also present on main branch as of March 2026)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions