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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Automation - using email Stationery 3

Status
Not open for further replies.

KarenLloyd

Programmer
Nov 23, 2005
141
GB
Hi there

I'm looking to automate faxes & emails through Outlook but I want to use an HTML file as the body of the message.

When creating an email from within Outlook, the basic file would automatically be picked up as the stationery, due to the Options settings. But when automated, the stationery setting is ignored.

As I need to insert text into the HTML file anyway that is fine. But how do I get the file into the body of the message from VFP(6)?

Can anyone help please?

Karen
 
Hi Mike

That's fantastic. I didn't know FILETOSTR() would handle HTML and the images as well.

Thank you very much.

Karen
 
FILETOSTR() will acquire the characters from ANY type of file.

If it should be an HTML file, then it will acquire everything that you could see from the HTML file if you were to open it in Notepad or something similar.

Then what you do with the string that is populated from the FILETOSTR() function is up to you.

What Mike has suggested above will work fine.

But it will not actually use pre-defined Outlook stationery. Instead it will send an HTML Email which can appear like stationary.

Good Luck,
JRB-Bldr
 
FileToStr() doesn't handle the images. If img tags in the html refer to files, you'll see images, of course. But that's not, because they are part of the HTML file.

Bye, Olaf.
 
Thank you JRB-Bldr

All I need is to be able to use the file as though it were the email stationery. The messages will then appear the same, whether they are generated in Outlook or from VFP.

Having used FILETOSTR()- I can also insert the actual message text into a space within the template using STRTRAN()

I'll post the code here for others soon as I finish it.

**

Also, thank you Olaf.

I understand what you say about the images. This only works because the HTML file includes web URLs for the image files.

It's been a couple of years since I've even looked at HTML, but your comments are very helpful.


Thanks again

Karen
 
In this example, the HTML file is used as the stationery in Outlook. This creates an email with the company logo and images (from URLs) and a blank space in the centre where it says "Type your text in here........."

In order to generate an email from VFP as though it were using the stationery, the HTML content is placed into a string and then modified to include the message.

In this example, the message body comes from a memo field.

Code:
#DEFINE olMailItem 0

myOLApp = createobject("Outlook.Application")
myOLItem = myOLApp.CreateItem(olMailItem)

WITH myOLItem

   .To = "name@companyemail.com"

   .Subject = "Email Subject"

   * 	Put the contents of the HTML stationery file into a string
   myHTMLBody = FILETOSTR("C:\fullpath\email_template.html")
   
   *	Get the message text (memo) - reformatting CR/LF to <br>
   myBodyText = STRTRAN(testdata.msg_text,CHR(13)+CHR(10),'<br>')
   
   *	Need to convert < > & " to &lt; &gt; &amp; &quot;
   myBodyText = CHRTRAN(myBodyText,'&','&amp;')		&&... etc
   
   *	Insert the message text into the HTML string
   myHTMLBody = STRTRAN(myHTMLBody,'Type your text in here.........',myBodyText)
   
   *	Add the body to the email
   .HTMLBody = myHTMLBody

   *	Add any attachment(s)
   .Attachments.Add("C:\fullpath\doc_name.doc")

ENDWITH
myOLItem.Send

RELEASE myOLApp
RELEASE myOLItem

* Some code originated from Peping's faq184-2557


Thank you everyone for your help on this.

Karen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top