Skip to content

feat: add attachment support to Resend adapter#113

Merged
ChiragAgg5k merged 2 commits intomainfrom
feat-resend-attachments
Apr 1, 2026
Merged

feat: add attachment support to Resend adapter#113
ChiragAgg5k merged 2 commits intomainfrom
feat-resend-attachments

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

  • Remove the exception that blocked attachments in the Resend email adapter
  • Add attachment handling: base64-encode file-based (getPath()) or string-based (getContent()) attachments and include them in the Resend API payload
  • Validate total attachment size against MAX_ATTACHMENT_BYTES (25MB), consistent with the SMTP adapter

Test plan

  • testSendEmailWithFileAttachment — sends email with a file-path-based attachment
  • testSendEmailWithStringAttachment — sends email with raw string content attachment
  • testSendEmailWithAttachmentExceedingMaxSize — verifies 25MB limit throws exception (passes locally)
  • Existing Resend tests remain unaffected

Resend's API supports attachments with base64-encoded content. Remove
the exception that blocked attachments and add proper handling with
MAX_ATTACHMENT_BYTES (25MB) validation, matching the SMTP adapter.
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR enables attachment support in the Resend email adapter by removing the blocking exception and implementing proper attachment handling that is consistent with the existing SMTP adapter.

Key changes:

  • Two-phase attachment processing: a first pass validates the total raw content size against MAX_ATTACHMENT_BYTES (25 MB), and a second pass builds the base64-encoded payload for the Resend API
  • Explicit error guards for both filesize() and file_get_contents() failures (both return false on error), throwing descriptive exceptions instead of silently producing corrupt results
  • The content_type field is included in each attachment object, letting the API/mail client use the declared MIME type rather than guessing from the filename
  • New tests cover file-path attachments, raw string-content attachments, and the 25 MB limit enforcement

All three issues raised in the previous round of review have been addressed. The implementation aligns well with the SMTP adapter pattern and the Resend API specification.

Confidence Score: 5/5

Safe to merge — all prior P1 issues are resolved and no new issues were found.

All three previous P1 findings (silent file_get_contents failure, silent filesize failure, missing content_type) are explicitly addressed in this revision. The implementation is consistent with other adapters in the codebase (SMTP), the error paths are properly guarded, and the new tests provide solid coverage of the main scenarios. No remaining P0 or P1 issues.

No files require special attention.

Important Files Changed

Filename Overview
src/Utopia/Messaging/Adapter/Email/Resend.php Removes the attachment-blocking exception and adds proper attachment handling: size validation with explicit filesize()/file_get_contents() guards, base64 encoding, and content_type field — all previous P1 concerns have been addressed.
tests/Messaging/Adapter/Email/ResendTest.php Replaces the old exception-throwing test with three new tests covering file attachments, string-content attachments, and the 25 MB size limit — test coverage is thorough and correct.

Reviews (2): Last reviewed commit: "fix: address PR review comments" | Re-trigger Greptile

- Add error handling for filesize() returning false on unreadable paths
- Add error handling for file_get_contents() returning false
- Include content_type field in Resend attachment payload
@ChiragAgg5k ChiragAgg5k merged commit de06865 into main Apr 1, 2026
3 of 4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the feat-resend-attachments branch April 1, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants