Skip to content

Conversation

@Vin-it-9
Copy link

Description

Adds type-safe attachment support with FileAttachment and InlineAttachment classes, improving API clarity and type safety for email attachments.

Changes

New Classes

  • FileAttachment - Type-safe regular file attachments with builder pattern
  • InlineAttachment - Type-safe inline attachments for HTML emails
  • ContentId - RFC 2392 Content-ID value object
  • EmailAttachment - Sealed interface for attachment types

Modified Classes

  • Email.Builder - Added overloaded attachment() methods accepting FileAttachment and InlineAttachment
  • Attachment - Added isInline() helper method

Key Features

  • String convenience method: .contentId("logo123") instead of new ContentId("logo123")
  • Builder pattern with field validation
  • Support for File/InputStream content loading
  • 100% backward compatible - existing Attachment API continues to work
  • Zero transport layer changes - internal storage unchanged (List<Attachment>)

Testing

  • Added comprehensive test suite (EmailAttachmentSpec.groovy)
  • Tests cover: conversion logic, attachment ordering, validation, backward compatibility
  • All existing tests pass (email, email-javamail, email-amazon-ses modules)

Example Usage

FileAttachment:

FileAttachment file = FileAttachment.builder()
    .filename("invoice.pdf")
    .contentType("application/pdf")
    .content(pdfBytes)
    .build();

Email.builder()
    .from("[[email protected]](mailto:[email protected])")
    .to("[[email protected]](mailto:[email protected])")
    .attachment(file)
    .build();

InlineAttachment:

InlineAttachment logo = InlineAttachment.builder()
    .filename("logo.png")
    .contentType("image/png")
    .content(imageBytes)
    .contentId("company-logo")  // String convenience method
    .build();

Email.builder()
    .from("[[email protected]](mailto:[email protected])")
    .to("[[email protected]](mailto:[email protected])")
    .body("<html><body><img src='cid:company-logo'/></body></html>")
    .attachment(logo)
    .build();

Related Issues

Closes #554

Checklist

  • Implementation complete
  • Tests added and passing
  • JavaDocs added
  • Backward compatibility maintained
  • No transport layer changes required

…nlineAttachment classes

- Add EmailAttachment sealed interface for strongly typed attachments
- Implement FileAttachment for downloadable files with builder API
- Implement InlineAttachment for embedded content with ContentId support
- Add ContentId value type for RFC 2392-compliant inline references
- Enhance Attachment with isInline() method for disposition checks
@graemerocher graemerocher moved this to Ready for review in 5.0.0 Release Nov 30, 2025
@graemerocher graemerocher requested a review from sdelamo November 30, 2025 22:27
@Vin-it-9 Vin-it-9 requested a review from sdelamo December 2, 2025 11:31
@sdelamo
Copy link
Contributor

sdelamo commented Dec 2, 2025

@Vin-it-9 could you change the base of this PR to 4.12.x ?

@Vin-it-9
Copy link
Author

Vin-it-9 commented Dec 2, 2025

@Vin-it-9 could you change the base of this PR to 4.12.x ?

I tried to change the base, but I can’t find a 4.12.x branch in this repo. Which branch should I use?

@Vin-it-9 Vin-it-9 requested a review from sdelamo December 2, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Improve Attachment Model (Clear Separation of Regular vs. Inline Attachments)

2 participants