Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - 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 
Mobile Linux 
App Generation ROI 
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 / 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 - Preparing your message


    (Page 2 of 4 )

    We’ll begin by setting our basic email fields: To, From, CC, BCC, etc.  These are the fields used to construct the email’s header.

    Properties

    object.To

    object.From

    object.CC

    object.BCC

    object.ReplyTo

    object.Subject

    object.Textbody

    object.HTMLBody

    object.Configuration.Fields.Item(schema)

     

    Methods

    object.Configuration.Fields.Update

    object.CreateMHTMLBody htmlbody

    object.AddAttachment file

    object.Send

    All of the properties listed above accept text strings and are used to set various email fields.  I’ll go into details about them as we use them.  These are much easier to learn when you see them in action.

    Set objMessage = CreateObject("CDO.Message")

    ' Set Email Headers

    objMessage.From = "sender@mymail.com"

    objMessage.To = "recipient@mail.com"

    objMessage.CC = "copyto@mail.com"

    objMessage.BCC = "blindcopy@mail.com"

    objMessage.ReplyTo = "replyto@mail.com"

    objMessage.Subject = "Test email with CDOSYS!"

    ' Construct Email Body

    objMessage.Textbody = "This is a test email using CDOSYS."

    Here you can see I’ve set the standard email fields.  Only the From, To, and Textbody fields are required.  The ReplyTo field is the address that replies should be sent to if you don’t want them going to the From email address by default.

    All of the email address fields may use any standard email address format:

    • "Full Name" <email@domain.com>
    • "Full Name" email@domain.com
    • Full Name <email@domain.com>
    • email@domain.com

    You may add multiple recipients to any of the address fields by separating multiple addresses with commas.  If you use any of the formats involving quotation marks, you will need to escape them in your script.

    The Textbody property accepts a single text string as a value.  This can have any number of carriage returns as needed.  The text string can be read from an existing text file, read from any TextStreamObject (such as a program’s output) or coded manually.

    object.AddAttachment localpath | remoteurl[, username, password]

    Want to add some attachments?  That’s no problem either.

    objMessage.AddAttachment "C:attachment.txt"

    AddAttachment can accept either a local file path or a valid URL.  If the URL is password protected, be sure to add the username and password as well.  You may call AddAttachments as many times as needed to add multiple attachments to your message.

    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

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT