Outlook HTML.Body

G

grahamproctor

In VBA (Office 2003), I am trying to create a new email and set the bod
text to a saved HTML document but my graphic is not being displayed.
have used the following combinations of code (each try is commente
out) but without success. If I use .mht and open the email in th
Outbox the graphic appears but when I save and reopen it, it appears a
a placeholder only, not the graphic.

I would appreciate any ideas. Thanks, Graham.

Dim fso As FileSystemObject
Dim ts As TextStream
Dim strText As String

Set fso = CreateObject("Scripting.FileSystemObject")

'Set ts = fso_OpenTextFile("g:\Medics Away\Mailin
Documents\RepplyF.htm", ForReading)
Set ts = fso_OpenTextFile("g:\Medics Away\Mailin
Documents\Repply.htm", ForReading)
'Set ts = fso_OpenTextFile("g:\Medics Away\Mailin
Documents\Repply.mht", ForReading)
'Set ts = fso_OpenTextFile("g:\Medics Away\Mailin
Documents\Repply.mht.doc", ForReading)
'Set ts = fso_OpenTextFile("g:\Medics Away\Mailin
Documents\Repply.htm.doc", ForReading)

strText = ts.ReadAll

mai1.HTMLBody = strTex
 
G

grahamproctor

Many, many thanks Dmitri and all the great advice you make available.

I have only one problem now:

how do I get the HTML text into the Body following the graphic?

Am I thick or is this stuff DIFFICULT ????

Graha
 
D

Dmitry Streblechenko

I am not sure I understand - what do you mean by "Body following the
graphic"? You do not split the HTML body into multiple part (before and
after), you set the whole thing.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

grahamproctor

Thanks again, Dmitri.

What I am trying to achieve is having a graphic at the top of the emai
body, immediately followed by text which has been customised wit
different fields from a database, dependent on the recipient and othe
parameters.

The uncustomised text is currently stored in a .htm and I hav
successfully customised this HTML in code, before putting it into th
HTML.Body. So conceptually, I am trying to append that HTML text to th
graphic already in the body of the email.

I tried before to have the graphic in the .htm but that wa
unsuccessful because the graphic just turned into a placeholder when i
reached Outlook. Funnily enough, the graphic did appear in the untitle
email when it was displayed from code but when I sent or saved it, th
graphic disappeared when it was in the Outbox.

I tried your other trick to make the graphic a watermark/background i
the body and that worked fine, except for sizing issues but that stil
left me with the problem of how to append the HTML text to th
HTML.Body without replacing the graphic which was already successfull
placed there.

I suppose I could try to combine the graphic and text into a .jpg i
code and then use your trick but how I would do that I have no idea.

Puzzling? Not for you!!!

All the best, Graham
 
D

Dmitry Streblechenko

So you really need to merge two HTML strings into one. You can either create
an instance of the IHTMLDocument2 object, load your data, then modify the
HTML (insert other HTML strings, etc) using DOM.
Or, if you simply need to insert an HTML substring at the very beginning
1. Find the position of the "<body" substring
2. Find the position of the next ">" character (this is needed to skip over
the <body> attributes)
3. Insert new HTML at that position + 1.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

grahamproctor

Hi Dmitry

The problem is I don't have 2 HTML strings, I have a graphic (.jpg
which your excellent advice has fooled Outlook into putting into th
HTMLBody but I still have the problem of how to get the customised tex
(HTML string) appended to that image. Whatever I do seems to replace th
contents of the HTMLBody and lose the graphic.

I have received many HTML emails which have a graphic (which i
actually a link to another site) followed by text and that would b
good.

At the moment I am completely stumped - using IHTMLDocument2 object an
DOM is technically beyond me at the moment without an example (I a
using VBA and the code in is Access).

Yours desperately,

Graham
 
D

Dmitry Streblechenko

I still don't understand: why can't you have both image and extra text in
HTML body?

<html>
<body>
Text before image
<p>
<img src="cid:MyTestCID">
<p>
Text after image
</body>
</html>

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

grahamproctor

Hi again, Dmitri.

I think it is because the PC on which Outlook is being used to send th
message holds the image on its disk and when the email is sent tha
image is not contained in the email message except by a reference. Tha
reference cannot be located by the email when the recipient gets it
hence the graphic appears as a placeholder.

I suppose if I put an image on the web server, I could reference i
with <a href ... /a>.

I suppose I could also create a link to somewhere if I could show th
link as the elusive graphic but I don't know how to do that.

Your method of changing the graphic attachment to be the HTMLBod
solves that problem because the graphic is sent with the email and doe
not reference back to the Outlook sender PC.

However, with your method, having cunningly converted the graphi
attachment to the HTMLBody, I cannot append the message to the body
only overwrite it.

Does that make any sense?

Respectfully, Graham
 
D

Dmitry Streblechenko

I still do not understand what the problem is: sample code at
http://www.outlookcode.com/d/code/htmlimg.htm does *not* "converted the
graphic
attachment to the HTMLBody", it simply makes sure that the image in HTMLBody
refers to an attachment instead of an external location.
Maybe you can give an example of what you need to do and show what you set
the HTMLBody to and what you want it to be.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top