Did you find this useful?
Socialize it today.

Send an Email Message Using VBScript

Friday, October 28, 2011

There may be instances where you need to automatically send a message from some type application or program. Or, you may want to send yourself an alert when a service suddenly stops on one of your critical Windows 2003 Server. Without some type of monitoring application or agent running on the system, you'll need some type of custom program or script to send out a message with pertinent information.

Here is an example of a script that uses CDO to send an email message from a computer using a remote SMTP server. Replace "smtp.mydomain.com" with the hostname of the SMTP server that you will be sending mail through. You can modify the other properties such as who the mail is from and who the mail is being sent to. Just copy and paste into a text editor such as Notepad, then save with the extention of .vbs.

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "service1@mydomain.com"
objEmail.To = "serveradmin@mydomain.com"
objEmail.Subject = "Service Is Down"
objEmail.Textbody = "The Service ### has stopped."
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.

Recommended Books & Training Resources

Microsoft WSH and VBScript Programming for the Absolute Beginner Advanced VBScript for Microsoft Windows Administrators