Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1288
  • Last Modified:

sending a html email from vbs

Experts,
I am trying to send a very simple html email message from my vb script.  However, when I try to send it, it tells me that the object does not support property or method: objMail.bodyformat.  I can send a text email just fine, I am just not sure where I am going wrong?  Any help is much appreciated.

Thank you,
Mike

Dim strHeader

'Query for Info
 'strHeader = "List of School Holidays for the Current Week."
 strHeader = "<HTML><u>List of School Holidays for the Current Week.</u><HTML>"
     MyBodyText = strHeader
     Subjectline = "List of School Holidays for the Week starting: " & Date()

'msgbox strAll

'mail code
Set Out = wscript.createobject("Outlook.Application")
WScript.Sleep(2000)
     Set objNameSpace = Out.GetNamespace("MAPI")
WScript.Sleep(2000)
     objNameSpace.Logon
WScript.Sleep(2000)
     'Set objMail = Out.CreateItem(olMailItem)
     Set objMail = Out.CreateItem(olFormatHTML)
     
WScript.Sleep(2000)
'msgbox "here"
     
           objMail.To = "test@test.com"
            'objMail.To = strTo
            objMail.Subject = Subjectline
            objMail.BodyFormat = olFormatHTML
            objMail.Body = MyBodyText
WScript.Sleep(5000)
'msgbox "here1"
            objMail.Send
WScript.Sleep(10000)
 'msgbox "here1"

msgbox "Mail was sent!"
     
     objNameSpace.Logoff
WScript.Sleep(10000)

     Set objMail = Nothing
     Set objNameSpace = Nothing
     Set Out = Nothing
     
0
uconnfb13
Asked:
uconnfb13
1 Solution
 
nmcdermaidCommented:
You may get a better response if you move this to a more appropriate are like VB programming.

This has absolutely nothing to do with databases.


I suggest that you open up the VBA editor (say in Excel), and add the Outlook application library in Tools/References.

In this way you can at least get some clues as to the valid properties and methods.


Also, have you defined the constant values beforehand? Unless you tell, VBScript does not know what this is:

olFormatHTML


You shuold have a line like his beforehand:

Dim olFormatHTML

olFormatHTML = 6 ' or whatever the correct constant value is
0
 
rockiroadsCommented:
u need to use HTMLBody, u dont set BodyFormat

objMail.HTMLBody = MyBodyText
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now