Skip to content

Conversation

Tangresh
Copy link

This PR adds support for inline attachment support in HTML emails.
I am not entirely happy with the API as it is, where the contentId property has to be set with a setter on the OutlookMessageAttachment and the contentId is the only thing distinguishing it from a regular attachment.
Maybe they should be saved in a Map in the OutlookMessage, because one does not want multiple inline attachments with the same contentId?

@ctabin
Copy link
Owner

ctabin commented Sep 25, 2025

@Tangresh
Hi, thanks for the PR !
First of all can you explain what is an "inline" attachment ? 🤔

@Tangresh
Copy link
Author

Sure!
When sending HTML emails, you might want to include images in your content. Inline attachments are a way to send your images as attachments in your email, such that you can reference them in the HTML content, using syntax like <img src="cid:CONTENT_ID">. This way you don't have to load the images from a CDN and mail clients generally display them instead of showing a warning and not loading the images.

The Content-ID is the identifier by which the images can be referenced and is set as Content-Id header for MIME messages and in the PidTagAttachContentId property of an attachment in MSG files (see MS-OCXMAIL, section 2.1.3.4.1.2 / https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcmail/96ee0694-0902-43d2-97d3-40f1fad626e7). The inline attachments also don't show up as regular images in mail clients.

@ctabin
Copy link
Owner

ctabin commented Oct 1, 2025

@Tangresh Can you please rebase on master to fix conflicts ? 🙏

@Tangresh Tangresh force-pushed the inline-attachments branch from 5ef6bc7 to 59d426a Compare October 2, 2025 09:20
@Tangresh
Copy link
Author

Tangresh commented Oct 2, 2025

@ctabin Done

Edit: That was sloppy of me, I'll have to fix that commit again.

@Tangresh Tangresh force-pushed the inline-attachments branch from 59d426a to 3d2caab Compare October 2, 2025 15:53
@Tangresh
Copy link
Author

Tangresh commented Oct 2, 2025

I have also tested my application with your updated master branch, looks like everything is still working.
Do you intend to release a new version soon?

@ctabin
Copy link
Owner

ctabin commented Oct 2, 2025

@Tangresh Thank you very much ! Yes I plan to integrate your PR and I'll do a new release right after.
ETA this week-end or next week.

Copy link
Owner

@ctabin ctabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tangresh I left a few comments :-)


final List<OutlookMessageAttachment> regularAttachments = getAttachments().stream()
.filter(att -> att.getContentId() == null)
.collect(Collectors.toList());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use JDK21.

Suggested change
.collect(Collectors.toList());
.toList();


final List<OutlookMessageAttachment> inlineAttachments = getAttachments().stream()
.filter(att -> att.getContentId() != null)
.collect(Collectors.toList());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.collect(Collectors.toList());
.toList();

Comment on lines +481 to +482
}
else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
else {
} else {

Comment on lines +201 to +206
message.setReplyTo(Arrays.asList("reply1@jotlmsg.com", "reply2@jotlmsg.com"));
message.setPlainTextBody("Hello,\n\nThis is a simple message.\n\n.Bye.");
message.setHtmlBody("<html><body>Simple body</body></html>");
message.addRecipient(OutlookMessageRecipient.Type.TO, "cedric@jotlmsg.com", "Cédric");
final OutlookMessageAttachment inlineAttachment = new OutlookMessageAttachment("picture.png", "image/png", new ByteArrayInputStream(new byte[0]));
inlineAttachment.setContentId("picture.png");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make a test without the plain text and with an html part actually using linking the png to show how it works ?

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