aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes org.apache.commons.mail.HtmlEmail embedding/rendering the images again and again  in every loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "org.apache.commons.mail.HtmlEmail embedding/rendering the images again and again  in every loop" Watch "org.apache.commons.mail.HtmlEmail embedding/rendering the images again and again  in every loop" New topic
Author

org.apache.commons.mail.HtmlEmail embedding/rendering the images again and again in every loop

Rakesh Rawat
Greenhorn

Joined: Dec 26, 2008
Posts: 1
Following program/code is adding the images repetitively. IF I send emails to three users userA, userB and userB and it attached 1, 2, 3 images respectively. Seems email object is embedding/rendering the images again and again in every loop.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

Welcome to the Ranch!
Could you please UseCodeTags next time? I've added them for you this time; see how easier it is to read your code.

The problem is that you are creating one single email object. You are adding (through the embed method on line 6) an image for each record. That's why you get an extra image for each user.
The solution is very simple. Move the creation of the email object from line 2 to before line 5, at the start of the loop body. This will create a new email object for each record. This email object is initially empty so only the single image is embedded. After the email has been sent and the loop body ends, the email object will be discarded along with all of its contents. The next record will start anew with an empty email object that you can fill from scratch again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.apache.commons.mail.HtmlEmail embedding/rendering the images again and again in every loop
 
Similar Threads
Displaying output in HTML
How to embed image (relative path) in an HTML e-mail?
Image as part of HTML email
Attache dynamic file to Jakarta Commons Email
want to generate html formatted email that supports outlook?