bbottema / simple-java-mail

Simple API, Complex Emails (Jakarta Mail smtp wrapper)
http://www.simplejavamail.org
Apache License 2.0
1.22k stars 266 forks source link

How to esclude embedded image in email #525

Closed francescodiperna closed 4 months ago

francescodiperna commented 4 months ago

Hi, I need help to understand how to exclude embedded images in a message read from inputStream of an EML file.

Here the code used:

Email email = EmailConverter.emlToEmail(inputStream);

        List<AttachmentResource> attachments = email.getAttachments();
        for (AttachmentResource attachment : attachments) {
........

Thanks

Francesco

bbottema commented 4 months ago

I'm not sure what your code is about, but the embedded images are in email.getEmbeddedImages();

One way to get the Email without the embedded images is by converting to the intermediate builder instead of the Email directly:

Email email = EmailConverter.emlToEmailBuilder(inputStream)
   .clearEmbeddedImages()
   .build();

Another way is to start with an existing Email:

Email email = EmailBuilder.copying(yourEmail)
   .clearEmbeddedImages()
   .build();
francescodiperna commented 4 months ago

Thanks