Building a Mass-Emailer in WSH
(Page 1 of 4 )
Are you tired of having to manually send the same email to multiple people? Or maybe you have a spreadsheet full of contacts and would like an easy way to send out a form letter without having to import all of the addresses into your email program. Or perhaps you’re just looking for a way to schedule an email that emails current sales totals to your staff. In any case, almost everyone has some kind of use for a mass-mailer.
You’re going to need the email script you we built in my last article, “Sending Emails Using CDO in WSH.” In case you missed it, you can download a base script here.

If you haven’t read the previous article, you may feel a little lost in this one. I will be recapping some important points, but for the most part I will only be covering new material.
Let’s get started by taking our previous script and packaging it into a nice subroutine. Since we’re going to be sending multiple emails at once, we’ll need an easy way to keep recalling this portion of our script. I’ve also replaced all data portions with corresponding variable names. You can see my subroutine here.
Sub SendMail
objMessage.From = strFromEmail
objMessage.To = strToEmail
objMessage.Subject = strSubject
objMessage.HTMLBody = strBody
objMesasge.AutoGenerateTextBody = True
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.mail.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
= 25
objMessage.Configuration.Fields.Update
objMessage.Send
End Sub
With that done, we can now piece together the beginning of the script. All I’m going to do is list my default variables and create the CDO message object.
strFromEmail = "My Name <me@mymail.com>"
strSubject = "Daily Sales Recap"
strBody = "C:salesdailyreport.htm"
Set objMessage = CreateObject("CDO.Message")
Here, I’m just assuming that dailyreport.htm is an HTML formatted document that I want to send as the body of my email. You could easily append to this as necessary or even include a text string containing a custom HTML message.
With our base script in place, we’re ready to get down to business.
Next: Creating a mailing list >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer