Computers & ProgrammingComputers & NetworkingVBScript

Sending an Email Message Using VBScript

There may be instances where you need to automatically send a message from some type of 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 extension of .vbs.

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "[email protected]"
objEmail.To = "[email protected]"
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") = _
"smtp.mydomain.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top