Tuesday, September 22, 2009

VBScript CDOsys Message Sending

'------------------------------------------------------
' Send CDONTS email in ASCII text or HTML format
'------------------------------------------------------
Const mailServer = "mailserver.domain.com"

Sub SendMail(sendto, sendfrom, subjectline, msgBody, msgFormat)
If (sendto <> "") and (sendfrom <> "") and (subjectline <> "") and (msgBody <> "") Then
Dim objMessage
Set objMessage = Server.CreateObject("CDO.Message")
objMessage.Subject = subjectline
objMessage.From = sendfrom
objMessage.To = sendto
If msgFormat = "TEXT" Then
objMessage.TextBody = msgBody
Else
objMessage.HTMLBody = msgBody
End If
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
Else
wscript.echo "error: insufficient parameters (sendmail)"
End If
End Sub

No comments:

Post a Comment