Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#114044 - 30/08/2002 00:05 Generating HTML mail messages with images
number6
old hand

Registered: 30/04/2001
Posts: 745
Loc: In The Village or sometimes: A...
Hi,

I have a request that some HTML and/or email gurus out there may be able to help me find some enlightenment on.

I have a Windows application that can generate and email as a HTML attachment a report (something like Crystal Reports, but not quite the same, but you get the idea).

I have noticed that I can easily include graphics (e.g. GIF or JPG etc files) in the report, which will be reproduced in the HTML generated by the application (which is then emailled), but the references to the graphic image files are all local filesystem references, as thats where the graphics are loaded from when the report is run.

However this all works fine, except if I email this html file/attachment to anyone outside the company, then the URLs to the graphics don't resolve anymore and so the graphics don't appear.

Now, I have tried embedding proper URL's as the source of the graphics that the application uses, hoping that that URL will be output in the HTML it generates to no avail.

So, I am faced with having to do some coding to work around this issue. I can capture the HTML that this outputs and change the HTML as required before its sent.


In doing some research on various approaches to solving this problem I've come to the conclusion that there are about 3 approaches I can take.

Approach 1.
Have a "search and replace" run on the HTML, replacing all local references(e.g. file://....) to the graphics with proper URL's referencing our website (e.g. www.mywebsite.com/graphics/....)

This has the main advantage that its pretty straight forward, like most HTML email messages that get sent these days its easy to see how to do it.

It has these disadvantages:

1. The recipient must be be "online" when viewing the message/attachment I send in order to see the graphics - as these are now URL's to a website.

2. I have to ensure that the graphics I use are all located on my website, where the URL I create says that they are, and any new graphics need to be copied up there or they can't be seen when viewing the message.

3. It sucks and I don't like it.

Approach 2.

Search the html, replace the URLs to files to be "local urls (no paths in the uls)" and then add the graphics to the email as attachments, which are referred to in the HTML message.
So that the graphics travel with the email message and can be thus viewed offline anytime.

Major advantage is that the mail is completely self-contained.

disadvantages are:
1. It could make the email message quite large, but in the cases we are using this the graphics will be quite small and the email in total will be under 50Kb.

2. Not all mail clients works the same way and while it may look ok in say Outlook, it may not display properly in another Windows mail client (Eudora), and possibly not at all well in a Linux graphical mail client (e.g. StarOffice)

3. This often does not survive the email forwarding process and the embedded links to the attached images gets lost/damaged.

Approach 3.

Search and replace the HTML, changing all URLs to local file to Embedded (inline) graphic objects in the html and then embed the graphic images inline in the HTML using base64 encoding or similar to keep everything in one place.

Major Advantage - this overcomes most of the issues/problems of approach 2, without taking much more room, and is probably very straightforward to do.

Disadvantages:
Other than the same as #1 in Approach 2

I can't see any other problems, except I am not sure if this is supported by any or even most mail clients out there.
Nor am I exactly certain how to code up the HTML "tag" I need to embed JPG or GIF (or PNG) files in the HTML in such a way that the average mail client/web browser can understand and render the graphics on the page.

So, can anyone help me with aproach 3, and/or suggets a better way.
And before you say: PDF, yes I agree, but its not a option for this application for all sorts of reasons I won't go into here.


Top
#114045 - 30/08/2002 03:05 Re: Generating HTML mail messages with images [Re: number6]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4172
Loc: Cambridge, England
Approach 2.

Search the html, replace the URLs to files to be "local urls (no paths in the uls)" and then add the graphics to the email as attachments, which are referred to in the HTML message.


This is how to do it. All modern mail clients and MTAs understand MIME. The specific issue of referring to attachments by relative URLs is in RFC 2557.

Peter

Top
#114046 - 30/08/2002 04:11 Re: Generating HTML mail messages with images [Re: number6]
tms13
old hand

Registered: 30/07/2001
Posts: 1115
Loc: Lochcarron and Edinburgh
You probably want multipart/related (I can't remember which RFC specifies this), or, if the images are very small, "data" URIs (ditto for RFC).

I'd recommend using MIME parts for the images you want to appear with your text/plain alternative (you're not sending HTML-only, are you?) and "data" URIs for decorative elements that are not themselves part of the content.

In HTML, you're limited to about 700 bytes in a base64 data URI, because of LITLEN 1024 in the SGML Declaration for HTML.
_________________________
Toby Speight
030103016 (80GB Mk2a, blue)
030102806 (0GB Mk2a, blue)

Top