*
The moose likes Other JSE/JEE APIs and the fly likes Image as part of HTML email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Image as part of HTML email" Watch "Image as part of HTML email" New topic
Author

Image as part of HTML email

Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
I am sending an email in HTML format using Java mail.
In this I have included an image using
<img />

the mail is going fine usng java mail api

If I view this email from my system, I am able to view the image (it seems to be picking the local path). but when I open this email on some other system, email does not display.

Can someone please let me know how to embed the image so that it opens on other system as well.

My code is as follows

Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
I also tried this but no good

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

<img> displays nothing without a src attribute.

You can include images in two ways:
1) as a link to a remote website. The src must point to the absolute URL of the image: <img src="http://www.coderanch.com/path/image.png">
Note that most email clients have options to not download these images until the user explicitly tells the client to download them.

2) as an inline image. The image is a special kind of attachment.
Now you can possibly do this with JavaMail, but to be honest, I don't know how. You may want to use Aoache Commons Email; the HtmlEmail class has several embed methods. The example from the HtmlEmail class' API:
This will embed two images: the my/image.gif image, and some PNG image.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
>> displays nothing without a src attribute.

"src" attribute was there in the tag but it did not display after posting.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Ah ok. Still, the rest of my post still holds (except the img tags, but the API page will show you the full code).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image as part of HTML email