Solved

sending a html email from vbs

Posted on 2006-10-25
2
1,227 Views
Last Modified: 2012-08-13
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
Comment
Question by:uconnfb13
2 Comments
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 17809083
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
 
LVL 65

Accepted Solution

by:
rockiroads earned 400 total points
ID: 17810118
u need to use HTMLBody, u dont set BodyFormat

objMail.HTMLBody = MyBodyText
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now