|
|
|
| Title : |
The purpose of this article is to describe the process in
creating scheduled mail-outs using Windows Scripting Host
(WSH) and the email features of the SMTP service's
CDONTS.NewMail object. |
| Categories : |
WinNT, IIS, Email, Web Servers |
 Boaz Yahav |
| Date : |
Apr 25th 1999 |
| Grade : |
5 of 5 (graded 1 times) |
| Viewed : |
5925 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Boaz Yahav |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
The information in this article applies to:
- Microsoft Internet Information Server versions 4.0, 5.0
-------------------------------------------------------------------------------
SUMMARY
=======
Windows NT Option Pack (NTOP) and Windows 2000 install by default a Simple Mail
Transfer Protocol (SMTP) service that can be used for a variety of purposes,
usually using Active Server Pages (ASP) for email-based HTML form handling.
The purpose of this article is to describe the process in creating scheduled
mail-outs using Windows Scripting Host (WSH) and the email features of the SMTP
service's CDONTS.NewMail object.
MORE INFORMATION
================
The following example will step you through creating a WSH script to send mail,
as well as a text file that you can update for the mail contents, and a
scheduled task to send the mail.
1. The first step in setting up any scheduled activity is to ensure that the
scheduler service is running"
a. Click "Start" on the task bar, then click "Settings" and "Control Panel"
b. Double-click the "Services" applet in "Control Panel"
c. Scroll down to the "Task Scheduler" service
d. Ensure that "Status" states "Running"
e. Ensure that "Startup" states "Automatic"
f. Click "Close" to exit the services applet and close "Control Panel"
2. Next, create a text file with the following contents and save it as
"C:\MAILOUT.TXT" on your computer.
<p>This is line 1.</p>
<p>This is line 2.</p>
3. The next step is to create the WSH script to read the text file we just
created. Copy the following code and save it as "C:\MAILOUT.VBS" on your
computer. To customize the sender/receiver, change the value of the "strFrom"
and "strTo" variables.
'--------------------------------------------------------------------
'
' Mailout using CDONTS.NewMail
'
'--------------------------------------------------------------------
' declare all variables
Option Explicit
Dim objSendMail
Dim strTo, strFrom
Dim strSubject, strBody
' mail constants (some are for reference)
Const CdoBodyFormatHTML = 0 ' Body property is HTML
Const CdoBodyFormatText = 1 ' Body property is plain text (default)
Const CdoMailFormatMime = 0 ' NewMail object is in MIME format
Const CdoMailFormatText = 1 ' NewMail object is plain text (default)
Const CdoLow = 0 ' Low importance
Const CdoNormal = 1 ' Normal importance (default)
Const CdoHigh = 2 ' High importance
strFrom = "someone@microsoft.com" ' change to your email address
strTo = "someone@microsoft.com" ' change to the recipient's address
strSubject = "Test Message" ' change to your subject
' this line calls the ReadFile() function to read the page contents
strBody = ReadFile("C:\MAILOUT.TXT")
' this line calls the MakePage() function to format the page as HTML
strBody = MakePage(strSubject,strBody)
' the following section creates the mail object and sends the mail
Set objSendMail = CreateObject("CDONTS.NewMail")
objSendMail.From = strFrom
objSendMail.To = strTo
objSendMail.Subject = strSubject & " (" & Date() & ")"
objSendMail.Body = strBody
objSendMail.BodyFormat = CdoBodyFormatHTML
objSendMail.MailFormat = CdoMailFormatMime
objSendMail.Importance = CdoNormal
objSendMail.Send
Set objSendMail = Nothing
' this function returns a properly formatted HTML page
Function MakePage(txtSubject, txtBody)
Dim txtTemp
txtTemp = "<HTML>" & vbCrLf
txtTemp = txtTemp & "<HEAD><TITLE>"
txtTemp = txtTemp & txtSubject
txtTemp = txtTemp & "</TITLE></HEAD>" & vbCrLf
txtTemp = txtTemp & "<BODY>" & vbCrLf
txtTemp = txtTemp & "<H2>" & txtSubject & "</H2>" & vbCrLf
txtTemp = txtTemp & txtBody & vbCrLf
txtTemp = txtTemp & "</BODY>" & vbCrLf
txtTemp = txtTemp & "</HTML>"
MakePage = txtTemp
End Function
' this function opens a file and returns the file's contents
Function ReadFile(txtFile)
Dim txtTemp, objFS, objFL
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFL = objFS.OpenTextFile(txtFile)
Do While Not objFL.AtEndOfStream
txtTemp = txtTemp & objFL.ReadLine
txtTemp = txtTemp & vbCrLf
Loop
objFL.Close
Set objFS = Nothing
ReadFile = txtTemp
End Function
4. Next you will need to create a task to schedule the mail-out to be sent. Open
a command session and enter something like the following examples:
a. The following task will run once at 9:00pm
AT 9:00pm CSCRIPT.EXE C:\MAILOUT.VBS
b. This task will run every Monday at 6:00am
AT 6:00am /every:M CSCRIPT.EXE C:\MAILOUT.VBS
c. This task will run on the first of every month at 1:00am
AT 1:00am /every:1 CSCRIPT.EXE C:\MAILOUT.VBS
5. Depending on the scheduled time that you chose for the task above, your email
will be sent when the time occurs.
For more information on Microsoft's scripting technologies, please see the
following web site:
http://msdn.microsoft.com/scripting/
|
|
| Index Server FAQ Categories : MS Index Server, WinNT, IIS, Web Servers | | | This Knowledge Base article will briefly describe the steps
involved to set up remote debugging for use with Visual
InterDev Version 6.0 Categories : WinNT, Debugging, IIS, Web Servers | | | How can i add mime types to IIS 3.0 and IIS 4.0? Categories : IIS, WinNT, Web Servers | | | Setup IIS using only 1 ip address and 1 ssl key but have
multiple websites Categories : WinNT, IIS, Web Servers | | | windows nt php/3 file upload script Categories : Filesystem, PHP, IIS, WinNT, Web Servers | | | How to use the IIS Exception Monitor Categories : IIS, Debugging, WinNT, Web Servers | | | enable/disable the cookies system-globaly Categories : IIS, Cookies, WinNT, Web Servers | | | how to activate connection pooling in IIS 3 and IIS 4, for access via ODBC to SQL Server 6.5
Categories : IIS, ODBC, MS SQL Server, Web Servers, Databases | | | Why do i get a "Save As" dialog box when I type in the url of a php3 file Categories : PHP Configuration, PHP, Apache, Web Servers | | | Email a user with out exposing email address Categories : PHP, Databases, MySQL, Email | | | Javascript URL and Email Validation Categories : Java Script, Data Validation, Form Processing, Email, URLs | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | PostgreSQL and apache web authentication source.
Categories : Authentication, PostgreSQL, Apache, Web Servers | | | Broadcast HTML Email Categories : PHP, Email, MySQL, Databases | | | POP3 Class Categories : PHP Classes, PHP, Email | |
|
|
|