how to extract embedded images in email body using java - jakarta-mail

I can see many ways to embed images into email but not extracting the embedded image from email body content using java. I'm able to extract the text content in email body but the embedded images is shown with tags and with a CID (component ID). I need to extract it and store as an attachment into DB. I think it should be done like calling the server to extract the content and I'm not sure of it. Please help me to get this done. Your help on this is highly appreciated.
I can see something like this in email headers for an image,
[cid:image002.jpg#01CE978E.097473A0]

Extracting an image is like extracting the content for any other body part. Find the correct MimeBodyPart and use the getInputStream method to read the bytes or use the saveFile method to save the contents to a file.
If that's not working for you, explain in more detail what you've tried and what happened. See also the JavaMail FAQ for debugging tips.

Related

display and save a local image into database in react js

I'am developing a blog website using react.js where users can post and comment ...
so we know that a user can comment with an image ,and let's say he want to upload a local image that stored in his machine,i want to display that image as a comment and save it into postgres database which i'am using for that.
My question is what are the steps that i should follow to achieve my purpose,thanks in advance.
If you have to do in simple steps, you can save the image to base64, its just string representation of an image. So it can be saved in DB directly and when you have to show it just decode the string and display it accordingly.
References :-
https://github.com/dankogai/js-base64#readme
https://scotch.io/tutorials/how-to-encode-and-decode-strings-with-base64-in-javascript
Alternatively, what you can do when user selects an image, then upload that image to your server and get the path to that(multipart file upload) and from path you can show it where you want to show.
References :-
how to send a multipart/form-data from React.js with an image?
I hope it helps, Thanks :)

is it possible to send a folder with email-ext or a dynamic report?

I'm trying to send an email notification with gradle report, If I attached only the index.html, I got the report like the image attached:
I think it depends from the folders with which the report is related,
I would like to send the report as:
Any ideas how can I do this? Any help will be really appreciated
Try using Html in the Content Type in your email section, in addition to this, you can display the html content in email body which will also display it in html format.
Please note that file path is relative to the workspace, if file resides in the root of your workspace, filename alone in the path will work, if it resides in a different location try something like this:
${FILE,path="target/surefire-reports/emailable-report.html"}

Want to send a table to outlook using javamail API

I am displaying some data from my database on an html table. Now I want to display a link and on clicking that, I want to open outlook application just like any other mailto link, but I want the table to come as content in my email.
After reading many posts I have come to know that it is not possible to send html content via mailto. So I think I will have to use Javamail API to construct a message. So I have two questions:
1. How do I construct a message via Javamail API with body having a table.
2. How do I open outlook windows App using javamail? All the examples I see on the internet are for sending the email directly.
Why don't you want your message to be html? You can use another rich text format if you think that's better. Otherwise you're stuck with formatting the table as plain text, uses spaces to line up the columns and ASCII characters to draw lines around the columns if you want that.
JavaMail can't open Outlook, but there are other ways to open Outlook from a Java program.

showing inline or embedded images of a mail body in jsp web page

I am polling an exchange server and reading mails from that, saving mail details like To, From , body i.e. either HTML source code or text/plain in database. Body source code I am showing in content editable div in presentation layer and hence mails are being displayed perfectly as in Outlook or Lotus Notes. But I am facing problem with embedded / inline images. As within html source code it is coming as cid:Image01.. hence I am not getting the actual path of images from where I can show that in DIV. Attachments coming as separate attachment but not showing within mail body.
Any idea of doing it? Would be better if any sample java code can be provided. I am not sure about the mechanism, how Outlook or Lotus Notes as a client are able to show those inline images?
Regards
Soumya
You need to process the html content and convert the cid: references into http: references to some URL that your application will use to fetch the corresponding part of the message.

How to embed an image into an Outlook HTML email message?

We have a Winforms application which supports dragging and dropping chunks of HTML into Outlook (HTML) mail messages.
Chunks of text are fine.
But how do we proceed with images? Let's assume we don't want to host the images online but instead we want to send them with the email message. Assume also that we do want to see the image inline, not as an attachment (where the recipient's email client supports that, of course).
If you look at the HTML source of an Outlook message there are "cid" tags for images (which point to the image as an attachment I guess), but how do we go about generating a cid/contentid?
If a manual step in the process is an option, you can do it like this:
create the HTML automatically or manually as a saved HTML file, with <img> tags that link to locally-saved image files
attach the HTML to an Outlook email using the 'Insert as text' option tucked away under the down-arrow on the "Insert" button when selecting the HTML file as an attachment.
This populates the HTML email with the HTML from the file and embeds all images. I believe this tool uses Base64 encoding to embed the images as described in Sam's email.
Depending on the workflow, this method might be easier than converting images to Base64 yourself.
Note that this method only works in Outlook for Windows, not Outlook for Mac.
You can embed images in a html email using a base64 encoder. Its quite complicated but you basically encode the image as a text string in the email which is then interpreted.
This does not work in all email clients though.
Take a look at this and see if its what your looking for:
http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/
EDIT
The updated campaign monitor post on the clients which work with base64 images.
For the last part of your question, "generating a cid/contentid" I know the only way is useing outlook itself (or Word as a text editor of Outlook) to get that.
I had faced this problem when I needed to insert our company logo beside my signature text on the email.
So, open Microsoft Outlook (office 2016 im ny case) go to File > Options > Mail > Compose Messages > Signatures button
or inside the Outlook New Message windows, go Insert > Picture
If you are using html to make your whole email, you can search google for the same image, and put this in there:
<img src="http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" alt="picture1" />
You can also, use photobucket to host images (if you have to). Basically, you HAVE to have a source for the image.

Resources