Problem solve Get help with specific problems with your technologies, process and projects.

VBScript does mail

You can send e-mail messages from your script, as this tip explains.

Please let us know how useful you find this tip by rating it below!

Use this sub to send e-mail messages from your script. This script works on Windows 2000, and may work on NT 4.0 if the correct CDO library is installed.

This sub requires the SMTPserver, From address, Recipient address, Subject, and Message be passed as arguments.

A couple of general comments:

  • The SMTP service does not need to be running on the same machine as the script.
  • Separate multiple recipients with a comma or semi-colon. For example:,

' Begin example
SMTPServer = ""
Recipient = ""
From = ""
Subject = "Test email"
Message = "This is a two line test message" & vbcrlf & "Did you get it?"

' To add an attachment update the full path and uncomment the line
' There is one line below that must also be uncommented

'attachment = "c: \ test.txt"

' Call Sub and pass required data
GenericSendmail SMTPserver, From, Recipient, Subject, Message

' Begin Sub
' ------------------------------------------------------------------
' Generic function to send mail using a remote
' SMTP server. Pass SMTPserver, From address,
' Recipient address, Subject, and Message as arguments
' ------------------------------------------------------------------
Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)

set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message

' To add an attachment uncomment this line
'msg.AddAttachment attachment

msg.Configuration.Fields ("") = SMTPServer
msg.Configuration.Fields("") = 2



End Sub

Patrick Sklodowski is a Microsoft Certified Systems Engineer with over eight years of industry experience. His specialties include Windows NT/2000, Active directory, SMS, Exchange and scripting. He is currently working as a Senior Engineer with a global provider of engineering solutions and specialized staffing.

Dig Deeper on Windows legacy operating systems

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.