Skip to content

Prevent Overwriting Custom Content-ID for Attachments #566

Open
@0VP0

Description

@0VP0

Issue:
When I set a custom Content-ID for attachments, it gets overwritten after building the email using EmailBuilder.buildEmail() and send it .


Steps to Reproduce

  1. Create an email with an attachment using EmailBuilder.startingBlank().
  2. Convert the email to MimeMessage and set a custom Content-ID for the attachment.
  3. Convert it back to an Email using EmailConverter.mimeMessageToEmail(mimeMessage).
  4. Send the email.
  5. The Content-ID is changed after building the email and sending the email.

Expected Behavior

The custom Content-ID should stay the same after building the email and sending the email.


Actual Behavior

The Content-ID I set for the attachment gets overwritten after building the email and sending the email.


Example Code

Email email = EmailBuilder.startingBlank()
    .from("sender@example.com")
    .to("recipient@example.com")
    .withSubject("Test Content-ID")
    .withAttachment("file.pdf", new FileDataSource("/path/to/file.pdf"))
    .buildEmail();

// Convert to MimeMessage
MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(email);
MimeMultipart multipart = (MimeMultipart) mimeMessage.getContent();

// Set the custom Content-ID
for (int i = 0; i < multipart.getCount(); i++) {
    BodyPart part = multipart.getBodyPart(i);
    if ("file.pdf".equals(part.getFileName())) {
        part.setHeader("Content-ID", "<custom-id-12345>");
    }
}

mimeMessage.setContent(multipart);
mimeMessage.saveChanges();

// Convert back to Email
Email updatedEmail = EmailConverter.mimeMessageToEmail(mimeMessage);

Request

  1. Prevent Overwriting: I need a way to keep the custom Content-ID I set for attachments. It should not be changed when build the email.
  2. Direct Option (Optional): If possible, I would like to set the Content-ID directly on the attachment without converting to MimeMessage, from the AttachmentResource resource directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions