Need help with VBS code to open Outlook

P

Patrick

Hi everyone!!
Quick question on the above code. Can I pass a text file to the body item.
Here is code:
============================
Dim ol, ns, newMail

Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")

Set newMail = ol.CreateItem(olMailItem)

newMail.Subject = "Testing sublect header"
newMail.TO="(e-mail address removed)"
newMail.Body = "testing body" -> **Here
newMail.DISPLAY
Set ol = Nothing

Could i say something like: newMail.Body=C:\test.txt

Meaning i would like to display in the body of this email the text included
inside that text file.

Can this be done?

Thx for all your help!!!
 
E

Eric Legault [MVP - Outlook]

You can with the Microsoft Scripting Library - use the TextStream object from
the FileSystemObject:

Dim objFS, objTS

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strStationeryFilePath, 1, False)

newMail.Body = objTS.ReadAll
objTS.Close
 
P

Patrick

Thx for the hlp Eric, this works greate.

Eric Legault said:
You can with the Microsoft Scripting Library - use the TextStream object from
the FileSystemObject:

Dim objFS, objTS

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strStationeryFilePath, 1, False)

newMail.Body = objTS.ReadAll
objTS.Close
 

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