By mastering VBScript, you can automate many mundane network administration duties. Here's how you can use a VBScript to automatically send e-mail.
- I have a backup or other scheduled job that I want to view the log files for, and I want to have them automatically emailed to me every day.
- I have a mail server that I need to test whether mail relaying is working (or not) as expected.
- I want to send an email or file to someone quickly, from a server, without installing or configuring an email client.
Running the script
Running the script is very simple. First, download it and extract the SendMsg.txt file. You'll then need to rename the file to SendMsg.vbs. We don't automatically save the file with that extension because many virus scanners will interpret a VBS inside of a ZIP file as being a virus. It's not. You're perfectly safe. Rename the file and you're ready to go.
To run the script interactively, simply double-click on SendMsg.vbs in Windows Explorer, or type cscript SendMsg.vbs (without the quotes) from a command prompt. Then simply follow the prompts.
If you want to run the script in a non-interactive mode (a scheduled job, for instance), a couple of slight modifications in the script will be necessary. Every line in the script that contains "InputBox" must be changed; eliminate the InputBox, and replace the entire function with just the string you need.
For example, lines 25 & 26:
objEmail.From = InputBox("Please type the SMTP
address of the sender." & vbCrlf & _
ï¿?ï¿?ï¿?ï¿?ï¿? "(Example:
Sender@yourdomain.com)", "FROM:")
would simply become:
objEmail.From
= "Sender@yourdomain.com"
Also, lines 36-42 would be completely eliminated, with the exception of line 40. This line (if attachments are needed) would simply become:
objEmail.AddAttachment
"<path>\filename.ext"
Additional resources
Be sure to check out other TechRepublic scripting articles:
- Reset Local Administrator Passwords with VBScript
- Bulk-Delete Stale Computer Accounts with VBScript & NetPWAge
- Add Global Groups to Computers with VBScript
If you want to get started with scripting, or would like access to an extensive repository of scripts, be sure to check out the Microsoft TechNet Script Center. If you need a scripting editor, check out VBSEditor by Koan Software (free), or PrimalScript by Sapien.