Monday, January 14, 2008

Sending Email from A VBScript

You can add this code to your scripts to send an email.

Dim strComputer, sTextBody, objEmail, strSMTPServer, strFrom, strTo, strSubject, strTextbody

strSMTPServer = "enter the smtp server here"
strFrom = "enter the from email address here"
strTo = "enter the to email address here"
strSubject = "enter the email subject here"
strTextbody = "enter the body of the email here"

Set objEmail = CreateObject("CDO.Message")
objEmail.From = strFrom
objEmail.To = strTo
objEmail.Subject = strSubject
objEmail.Textbody = strTextbody
objEmail.AddAttachment "to add an attachment to the email, type in the file path"
objEmail.Configuration.Fields.Item("") = 2
objEmail.Configuration.Fields.Item("") = strSMTPServer
objEmail.Configuration.Fields.Item("") = 25

Set objEmail = Nothing

No comments: