I want to send an outlook email using VBScript. The body of the email should contains the contents of a text file, say sha.txt
. Below is the code I am using but it's giving me this error:
Run Time error '287': Application-defined or Object defined error
Sub email1()
Dim outobj, mailobj
Dim strFileText
Dim objFileToRead
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Users\sonu\Desktop\auto\sha.txt", 1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
Set objFileToRead = Nothing
With mailobj
.To = "user@user.com"
.Subject = "Testmail"
.Body = strFileText
.Send
End With
'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing
End Sub