How to Send an Email using Java MailAPI with Large Image as an Attachment

The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. The JavaMail API is available as an optional package for use with Java SE platform and is also included in the Java EE platform. The JavaMail 1.4.5 release contains several bug fixes and enhancements.

Sometime back I’ve written a Tutorial on Send an email using Gmail SMTP (TLS Authentication), but without Image Attachment. Below Java Tutorial will help you send a Large Image with an email as an attachment.

Sometimes we want to attach an image in the email and then use it in the email body itself. You must have seen so many emails that have image attachments and are also used in the email message. The trick is to attach the image file like any other attachment and then set the Content-ID header for image file and then use the same content id in the email message body with <img src='cid:image_id'>.

Here is a simple Java Program:

Output:

Example Screenshot:

JavaMailAPIwithImage Crunchify Example How to Send an Email using Java MailAPI with Large Image as an Attachment

If you enjoyed this post, make sure to subscribe to Crunchify's RSS feed.