How to Create an Email in a VBScript
Visual Basic Scripting (VB Scripts) is a type of Visual Basic programming that is used in text files. The Windows operating system recognizes the scripts as executables and runs the lines of code on the local computer. These scripts are used in networks and added to machines to automate login procedures. VB Scripts can also send emails. The scripts use an email component called CDO. Using CDO, you can send an email from a VB Script file.
Instructions
-
-
1
Open Notepad or an existing VB Script file to add the email commands to the code. If this is a new file, save the new file to a location on the hard drive. Ensure you save the extension for the file as vbs, which triggers Windows to run the code instead of treating it like a normal text file.
-
2
Create the main mail CDO object variable. This instantiates the object, which means you load it into memory and the coder is able to call all the properties and methods associated with the object. Below is the code to instantiate the CDO object:
Set cdoMail = CreateObject("CDO.Message") -
-
3
Set the "To" and "From" properties for the CDO object. The "To" and "From" properties set the recipient and sender values. This is the code to set these values:
cdoMail.From = "your_name@your_domain.com"
cdoMail.To = "test@your_recipient.com" -
4
Set the subject for the email. This is the same as entering a subject for an email in a regular client. The code to set the email subject is:
cdoMail.Subject = "My Email Subject" -
5
Send the message. Once the email is set up, you still need to call the "Send" function. The send function packages the email and sends it to the recipient. The code is:
cdoMail.Send -
6
Save the file to a location on your hard drive. To test the code, double-click the file on your hard drive and an email is sent to the recipient listed in the code.
-
1
Tips & Warnings
The CDO object uses the default outgoing and incoming server settings on the local machine. If the computer is not connected to the Internet, the process will fail.