Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Sending Emails Using CDO 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

Sending Emails Using CDO in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-04-03

    Table of Contents:
  • Sending Emails Using CDO in WSH
  • Preparing your message
  • Configuring the SMTP server
  • Sending HTML messages

  • 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


    Sending Emails Using CDO in WSH - Configuring the SMTP server


    (Page 3 of 4 )

    In order to send the message, CDO needs to know some information about the SMTP server you’ll be using to send it.  While this can be a local server, in most cases it’s probably going to be remote.

    objEmail.Configuration.Fields.Item _

       ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    objEmail.Configuration.Fields.Item _

       ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _

       "smtp.mymail.com"

    objEmail.Configuration.Fields.Item _

    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    The Configuration.Fields Property returns a collection of settings used to configure your email message (or newsgroup post as CDO also supports NNTP) for SMTP.  There is a long list of configurations available.  I’m only showing you the ones you’ll need most.

    For more information I suggest checking out Chapter 6 of Brian Knittel’s book “Windows XP Under the Hood,” a fantastic Windows Scripting book available from Que.  The chapter, titled “Messaging Objects,” takes an in-depth look at the CDO object.  You can pick it up at both Barnes&Noble and Amazon.com.

    The sendusing property will almost always be set to 2.  This tells CDO to send your message directly to the SMTP server that you provide.  A value of 1 would indicate to drop the message into the IIS SMTP service pickup directory instead.

    The smtpserver item accepts either a valid hostname or IP address for the SMTP server.  The smtpserverport item should be set to whatever port your SMTP server operates on.  In most cases this is port 25.

    If your SMTP server requires authentication, you’ll need to add a few more configuration fields.

    objEmail.Configuration.Fields.Item _

    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

    objEmail.Configuration.Fields.Item _

       ("http://schemas.microsoft.com/cdo/configuration/sendusername") = _

       "user"

    objEmail.Configuration.Fields.Item _

       ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = _

       "password"

    The smtpauthenticate item accepts one of three cdoProtocolsAuthentication values.  Use its default 0 for no authentication, 1 for basic (clear-text) authentication, or 2 to use the credentials of the currently logged on user.

    If your outgoing mail server requires a secure connection, you’ll also need to set the smtpusessl item.  It accepts a Boolean value and defaults to false.

    objEmail.Configuration.Fields.Item _

       ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

    After setting all of the configuration items, you’ll need to make a call to the Update method in order to save those settings in the Fields collection.

    objEmail.Configuration.Fields.Update

    objEmail.Send

    Finally, you can make a call to the CDO object’s Send method and send your message zipping off through cyberspace.  One nice thing about using CDOSYS instead of CDONTS is that you can use this as many times as necessary.  CDONTS only supports sending one message at a time and requires you to recycle the message object each time you need it.

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


       · In this article I'm going to show you how to add email capabilities to your scripts...
       · This is very good, but the object name on page 3 should be objMessage not...
       · You are exactly right. Thanks for the correction.
     

    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-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek