• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image as part of HTML email

 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also tried this but no good

 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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.
 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> displays nothing without a src attribute.

"src" attribute was there in the tag but it did not display after posting.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ok. Still, the rest of my post still holds (except the img tags, but the API page will show you the full code).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic