Open
Description
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
- Create an email with an attachment using
EmailBuilder.startingBlank()
. - Convert the email to
MimeMessage
and set a custom Content-ID for the attachment. - Convert it back to an
Email
usingEmailConverter.mimeMessageToEmail(mimeMessage)
. - Send the email.
- 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
- 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.
- 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
Labels
No labels