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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 5
    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

    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway