Need help with VBS code to open Outlook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!!!
 
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
 
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
 
Back
Top