display image in html template

Hi,

I am trying to send an email with HTML template as an attachment. This is working fine with text messages. Now Im trying to add images to the HTML and Iam not getting the images in the html template.

Here is the approach I followed.

template:
/packages//templates/sample.html

this html refers image1.jpg using

I have placed the image in
/packages//pub/images directory.

I have addded .access file and mentioned * Anonymous to both pub and images directory.

but still this is giving error.

Is there anything else I need to do or am I missing anything? any expertise?

Regards
Sai Arun

Your img tag is going to need to be an absolute and complete path for anything outside of IS to be able to retrieve the image. That means using a full URL including the hostname and port.

I am not sure I understand you correctly, so let me make my answer conditional to the presumption:

Presumption
You are generating this HTML which will be sent as an attachment in an email. The attached HTML is required to contain image(s).

Treasure Hunt Clue
Using the image tag to give path to the image file will not work, because when the recipient of the email will open the HTML, the image path wouldn’t be found. To achieve this, you will have to create mime object for image and populate the contents of this mime with data of the image. Then in your HTML you will have to give the id of this mime object as img src. Effectively, you are embedding the image.

Alternatively, you can host the image at a location that is accessible to the recipient of the email without requiring a userid/password and then use the absolute path of the image in your html.

I have used this approach in the past - can’t recall the exact steps right now… but this should give you a direction.

~Rohit

Approach One
If you want to send the html as an attachment, you’re gonna have use the full path as Rob said. Though you’re gonna have to bear in mind is that the resource (your server & the image on it) is accessible to the recipient of the mail. For example, if the image is logo.jpg in pub/images folder of IS package MyPackage, the following will work:

However, the above approach will not work if your IS server is not accessible to the recipient of the email.

Approach Two
Alternatively you can send the entire email as an HTML and embed the image in the HTML. Use the MIME services to create a multipart/related mime data with first part containing the html and the next one containing the image data… use the Content-ID header tag to specify an id to the image data part and use this id as the img src in the HTML.

HTH ~Rohit

Another approach:
Attach an image to the email (encode it base64, give it a name and remember to put in the right content type).
In your HTML code use the Content ID to point to any attachment in your email:
Imagine the image you are attaching is called B2B.jpg, you would have to use it like this:

It works perfectly for me.
Regs,

Master F

Dear Friend,

                  i have requirement to send email and to 

display the image in the body of the html content. i don’t which service to get Content-ID. give the details information of sending email with image.
Thanks.

There were three alternatives given already in this thread. You mentioned that one of them would not work for you for some reason. What about the other two. Can you explain why they would not work?

Mark

thanks for your reply

   please find the TESTFILE.zip. this file contains my progam with. i dont where i am mistaking.

my Requirement:

         This program do the image as an attachment in email. but not display the image in attachment. can you explain the where to get CONTENT-ID or how to use it. 
                   Thanks in advance.

Here is our solution and It works perfectly for us.

  1. getFile
  2. attach bytes to content of smtp attachment
  3. set file name to be remember
  4. set encoding to based64
  5. invoke smtp

hi masterf

can you tell me how do u set the Content ID to attachment in mail?