PHP and MySQL Code

Start typing to search for PHP and MySQL Code Snippets and Articles Search

Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
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 : 15664
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

Submit your own code examples  Submit your own code examples 

The information in this article applies to:

- Microsoft Internet Information Server versions 4.0, 5.0


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.


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 = "[email protected]" ' change to your email address
strTo = "[email protected]" ' 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

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
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

b. This task will run every Monday at 6:00am

c. This task will run on the first of every month at 1:00am

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:

How can i add mime types to IIS 3.0 and IIS 4.0?
Categories : IIS, WinNT, Web Servers
enable/disable the cookies system-globaly
Categories : IIS, Cookies, WinNT, Web Servers
windows nt php/3 file upload script
Categories : Filesystem, PHP, IIS, WinNT, Web Servers
Index Server FAQ
Categories : MS Index Server, WinNT, IIS, Web Servers
How to use the IIS Exception Monitor
Categories : IIS, Debugging, WinNT, 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
Setup IIS using only 1 ip address and 1 ssl key but have multiple websites
Categories : WinNT, IIS, 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
Broadcast HTML Email
Categories : PHP, Email, MySQL, Databases
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
POP3 Class
Categories : PHP Classes, PHP, Email
Caldera Openlinux 1.2 Standard
Categories : Web Servers, MySQL, PHP, Apache, Databases
simple script to send emails via a html-form to different users
Categories : Email, MySQL, PHP, Databases
email validator check checker email e-mail email address
Categories : PHP, Email, Regexps
How to use your own 404 Error file from .htaccess.
Categories : Apache, Web Servers