Using VBScript to Send Emails with Gmail

This article was written on August 20, 2010 by CyberNet.

I normally don’t post scripts and batch files that I use, but I wanted to share this particular script because I use it all the time. VBScript files are nice because typically they are simply coded, and work across virtually all Windows-powered machines. You just have to throw the code in a .VBS file, and from there it can be executed in your batch files very easily.

The contents of the file are below, and once set up you’ll be able to send emails using any Gmail account straight from the command prompt. In the code there are two things that you need to configure: the email address and password of the account you want to send as. When executing the VBScript file you simply pass it three parameters: recipient email address, subject line, and the body of the email. There is an optional fourth parameter that it accepts which is the file path to a file you want to attach to the email. That’s it.

Why do I use this all the time? I can easily call this file from other scripts or batch files so that it sends me an email notification whenever something completes. Sometimes I use it just to have a nice history of when some of my batch files complete (or to verify that they even ran), but other times I will insert “dynamic” text into the body of the email. For example, if an error occurred I may have it put the error message in the body of the email. An alternative to that would be attaching a log file using the optional fourth parameter.

The nice thing about the way this script works is that you’ll be able to send emails without setting up an SMTP server on your machine. Of course you won’t be able to send out mass quantities of emails since Google limits you to around 500 sent messages per day, but that should be more than adequate for personal purposes.

Let’s take a look at what the code looks like…

Code begins here:

'Usage: cscript sendemail.vbs <email_recipient@example.com> "<subject_line>" "<email_body>" "<optional:email_attachment_path>" 'Ex. No attach: cscript sendemail.vbs example@gmail.com "test subject line" "test email body" 'Ex. W/ attach: cscript sendemail.vbs example@gmail.com "test subject line" "test email body" "c:\scripts\log.txt" '*********** '****CONFIGURE THE FROM EMAIL ADDRESS AND PASSWORD Const fromEmail = "email_sender@gmail.com" Const password = "password" '****END OF CONFIGURATION '*********** Dim emailObj, emailConfig Set emailObj = CreateObject("CDO.Message") emailObj.From = fromEmail emailObj.To = WScript.Arguments.Item(0) emailObj.Subject = WScript.Arguments.Item(1) emailObj.TextBody = WScript.Arguments.Item(2) If WScript.Arguments.Count > 3 Then emailObj.AddAttachment WScript.Arguments.Item(3) End If Set emailConfig = emailObj.Configuration emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = fromEmail emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password emailConfig.Fields.Update emailObj.Send Set emailobj = nothing Set emailConfig = nothing

^ That is the end of the code (Download the Script) ^

You can see that the code starts with example usage of how you can call the VBScript file. Given the nature of executing VBScript files you may or may not have to include the “cscript” portion, but in general you are always better off having it there to ensure that it will run on your computer just fine. Here’s an example of what it looks like when being executed from the command prompt:

vbscript send email gmail.png
Note: The “sendemail.vbs” file was located at the root of the C Drive when I ran this.

Armed with this script you should be able to take it and throw it into batch files, or call it from anywhere that can execute things via the command line. One thing you may want to consider is creating an extra email account just for sending these emails. Not only will that keep your “sent mail” clean in your primary Gmail account, but it will also be a bit more secure since the password for the sender account is stored in plain text within the script.

Here is a nicely formatted version of the VBScript from above that you can download, and have all ready to go for you (after you fill in the two email/password inside the script file, of course):

Download a Zipped Copy of the VBScript

Copyright © 2013 CyberNetNews.com

BioShock creator confirmed as scriptwriter for Logan’s Run remake

BioShock creator confirmed as Logan's Run scriptwriter

The mind behind BioShock‘s Big Daddies and BioShock Infinite‘s Songbird is apparently also getting behind the script for a Logan’s Run film remake. Irrational Games creative director and head Ken Levine is working on a Logan’s Run remake script, Irrational confirmed to Engadget today, which he was tapped to pen by Warner Bros. “I can confirm that the information is indeed correct, but unfortunately there is no other information we can share or comment to be given at this point,” the rep told us.

According to a Deadline report that surfaced earlier this week, Levine is continuing his work at Irrational in the meantime — the studio’s working on a few content packs for its latest BioShock release, and assuredly other things — while Jon Berg oversees the Logan’s Run project. Also in the report: this remake has been in the works for some time, though Levine’s addition is new to the project.

In case it wasn’t already clear, there’s a pretty sweet Logan’s Run movie (based on the original 1967 book) starring Michael York as “Logan 5.” The very, very mid-’70s poster for that film is cropped just above.

Filed under: , , , ,

Comments

Amazon’s Storyteller Helps You Turn Your Script into a Storyboard

You might be a budding writer with a script for what you think could be the next big thing in movies. But making the words leap out of the page and onto a storyboard is difficult if you don’t have the artistic skills to carry out your concept. The Storyteller tool that Amazon has just debuted is designed to help you out with this.

amazon storyboard 1Bring your ideas and vision to life by clicking through the Storyteller’s various menus and adding pre-drawn and custom backgrounds, characters, props, and settings. This will help you sell your story and hopefully find a director or producer who’ll be willing to work on your film once they see what your concept is all about.

amazon storyboard 2

Amazon Studios director, Roy Price, explains why they came up with the tool: “We’ve found that many writers want to see their story up on its feet in visual form but find it harder than it should be to create a storyboard. Storyteller provides a digital backlot, acting troupe, prop department and assistant editor – everything you need to bring your story to life.

Sounds neat, doesn’t it? You can try out Amazon Storyteller here.

[via Dvice]