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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

Set objEmail = Nothing

No comments: