Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to populate Outlook body with HTML file contents

Status
Not open for further replies.

PennyH

Programmer
Joined
Oct 6, 2004
Messages
6
Location
US
I am trying to help a former collegue with a system that isn't quite working right for them right now.

They have an web page that is used only internally, that takes as input several xml files. These xml files indicate different options that the end user can select to pick pre-defined canned items and generate what will appear to be a unique email for an individual.

This application then determines which options where selected, the email address, and subject line, and it will create a "mailto:" URL to generate the email. It goes through and creates the body of the email in two ways... one is URL sensitive so that it can be sent through the URL and is simple plain text, the other is HTML so that the user can choose to preview the body in an explorer window before generating the email. The mailto: link is then activated... and it brings up Outlook with the subject, to address, and body.

Their first issue is that if they choose too many items, they hit an error when the URL is greater than 1800 characters. To work around it, the designer put in a test for 1800 characters, and if so, tells the user to use preview mode, highlight the text, copy and paste it into the email that is generated with only the email address and subject.... they're getting tired of hitting that issue... usually they don't preview... so this means that they have to cancel the first email - then go back and hit preview; and start over.

Their second issue is that the URL generated email is plain text.

I've added code that takes the HTML email formatted string and generates a text file with it and saves it to their desktop.

In Outlook Express, I can do an insert object manually and insert the HTML file - and send. In Outlook 2003, Insert Object isn't an option. I need to be able to either use scripting or VBA macro, or something where with a click of a button it can insert the contents of the file in HTML format into the body of the email...

any ideas the best way to approach this?

Penny
 
Have you tried to play with the HTMLBody property of the MailItem object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I did find a way using the HTMLBody property ... thank you...

Here's my code in case someone comes across this post and has similar needs.

Dim olApp As Outlook.Application
Dim objMail As Object
Dim fs As Object
Dim f As Object
Dim ts As Object
Dim strHTMLBody As String

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("c:\newEmail.htm")
Set ts = f.OpenAsTextStream()
strHTMLBody = ts.ReadAll
'MsgBox strHTMLBody
ts.Close
Set f = Nothing
Set fs = Nothing

Set olApp = Outlook.Application
Set objMail = olApp.ActiveInspector.CurrentItem

objMail.HTMLBody = strHTMLBody
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top