View Full Version : VB Script problem - CreateObject("Outlook.Application")

03-14-2005, 04:25 PM
Hi all. I'm at my whits end with this. I'm not to sure if its even a script problem. Simply I want to send an email using this set-up below. However, Outlook the pain in the buns is hitting me with warning message. Is there any way i can stop this form happing.????

Please have a look at my working script.

<script language="vbscript">

Sub SendMailOutlook(aTo, Subject, TextBody, aFrom)

'Create an Outlook object
Dim Outlook 'As New Outlook.Application
Set Outlook = CreateObject("Outlook.Application")

'Create e new message
Dim Message 'As Outlook.MailItem
Set Message = Outlook.CreateItem(olMailItem)
With Message
'You can display the message To debug And see state

.Subject = Subject
.HTMLBody = TextBody

'Set destination email address
.Recipients.Add (aTo)
If Len(aFrom) > 0 Then .SentOnBehalfOfName = aFrom

'Set sender address If specified.
Const olOriginator = 0
'If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator

'Send the message
End With
End Sub

sub sendit

readytosend = "yes"

HTML = HTML & "<html>"
HTML = HTML & "<head>"
HTML = HTML & "<title></title><style>td {font-family:verdana} body {font-family:verdana}</style>"
HTML = HTML & "<center><b>Escalation Form</center></b<p>"
HTML = HTML & "</head>"
//HTML = HTML & "<table width=600 cellpadding=1 bgcolor='white' border=0 cellspacing='0'>"
HTML = HTML & "<body bgcolor=""FFFFFF"">"
HTML = HTML & "Name:<b>" & myform.txtName.value & "</b>"
HTML = HTML & "</table>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"

if readytosend = "yes" then
SendMailOutlook "emailaddress@blah.co.uk", "Escalation",HTML, ""

msgbox "The Escalation has been sent. Check your sent items for a copy of the message"

end if

end sub

td {font-family:verdana}

<title>Escalation </title>
<h3><center><font face=verdana>HTA Escalation Form</center></h3></font>
<form name="myform">
<table align=left>
Name:</td><td> <input style="border-left:0; border-right:0; border-top:0; font-family:verdana; font-size:12pt" size=45 type="text" name="txtName">

<td align=right>
<input type="button" onclick="sendit" value="Send">