Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Outlook mail in text/html format 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
How do I send a message that consists of html code so that outlook will interpret the html code rather than displaying the code itself (i.e. "content-type: text/html" rather than "content-type: text"). (Note that in my application, sending it as an attachment won't work.) Below is the code I'm using:

Dim objOutlk
Dim objMail
Dim strMsg
Const olMailItem = 0

Set objOutlk = createobject("Outlook.Application")
Set objMail = objOutlk.createitem(olMailItem)

objMail.To = "somebody"
objMail.subject = "This is my subject line"
objMail.body = &quot;<html><head></head><body>Hello world</body></html>&quot;
objMail.send
objMail = nothing
Set objOutlk = nothing
 
You sound like you already have your answer, you're just not using it. :)

Set oOutlook = CreateObject(&quot;Outlook.Application&quot;)
Set oMail = oOutlook.CreateItem(0)
oMail.To = &quot;you&quot;
omail.subject = &quot;subject&quot;
oMail.HTMLBody = &quot;<html><head><META HTTP-EQUIV=&quot;&quot;Content-Type&quot;&quot; CONTENT=&quot;&quot;text/html;charset=Windows-1252&quot;&quot;><title>Hello</title></head><body><SCRIPT LANGUAGE=&quot;&quot;VBScript&quot;&quot;>Sub Sucker()Msgbox &quot;&quot;You are so gullable!&quot;&quot;,0,&quot;&quot;Sucker&quot;&quot;End Sub</SCRIPT><input type=&quot;&quot;button&quot;&quot; id=&quot;&quot;Sucker&quot;&quot; name=&quot;&quot;Sucker&quot;&quot; value=&quot;&quot;Click Me!&quot;&quot; onclick=&quot;&quot;Sucker&quot;&quot;></form></body></html>&quot;
oMail.Send
Set oMail = Nothing
Set oOutlook = Nothing Jon Hawkins
 
Thanks. I see my mistake. Instead of using the body property (oMail.Body) I should have used the HTMLBody property (oMail.HTMLBody).
 
Hi Jon,

Need some help. The above code works fine in older versions of Outlook. But in Outlook 2000, it seems to be giving me a pop-up menu telling me that an application is trying to automatically send an email and asking me click yes/no/cancel - and without clicking the email doesn't go. Please help me. Thanks.
 
Pradipto - see faq184-1156

You can effectively use the code above, if you do NOT apply SP2 to Outlook 2K. Jon Hawkins
 
hi, the example is only applied to single line of html/text codes. What is the sollution if i would like to insert mulitple lines of html/text codes (eg, html codes created at M'soft Frontpage) ? I found error when paste it to oMail.HTMLBody since my html/text files is very big and consist of spaces, &quot;, ....
 
You'll need to format your HTML code especially if it contains double quotes (&quot;). You can either replace these with this(&quot;&quot;), as shown in the example above(I've never tried this myself) or use single quotes('). Also FrontPage puts numbers in quotes (eg size=&quot;10&quot;) you can remove the quotes entirely from numbers except where they are prcentages (eg &quot;100%&quot;), you'll need to leave the quotes in there.
Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top