Windows Scripting
  Home arrow Windows Scripting arrow Building a Mass-Emailer in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Building a Mass-Emailer in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2007-04-04

    Table of Contents:
  • Building a Mass-Emailer in WSH
  • Creating a mailing list
  • Customizing a form message
  • Wrapping things up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Learn how to create a mass-mailer using CDO in WSH. You'll be able to build and...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek