ASP test mail script CDONTS – CDO for Windows Server
Anthony Gee | Feb 26, 2010 | Comments 6
This tutorial will provide you with a test ASP CDONTS mail script which will help you to troubleshoot or just test whether the mail server is running fine on your Windows server.
Why the script is called CDONTS? Here is some description:
CDO (Collaborative Data Objects) is a programming interface from Microsoft for accessing MAPI-based e-mail, calendaring and scheduling servers. Originally called \"OLE Messaging\" and \"Active Messaging,\" CDO wraps the Enhanced MAPI library into a COM object that provides the ability to dynamically create Web pages. CDO is server oriented whereas MAPI has a client orientation.
CDONTS (CDO for Windows (NT) Server) is the SMTP version of CDO. It is widely used to send text e-mail and HTML-based e-mail from ASP pages. CDONTS was introduced with Internet Information Server 4 (IIS4) to make the Web server software fully Internet compliant.
Anyway, the script is written in one file which calls itself. It is divided in two parts – HTML form and ASP processor section.
Here is the form part(I keep it simple since I am using this only for testing purposes).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1250"> <title>Mail example</title> </head> <body> <form action="simple_test_mail_script.asp" method="post" name="form" id="form"> Your mail:<br> <input name="from" type="text" id="from"> <br><br> Recipient:<br> <input name="to" type="text" id="to"> <br><br> Subject:<br> <input name="subject" type="text" id="subject"> <br><br> <br> <input type="submit" name="Submit" value="Submit"> </form> <br> <br> </body> </html> |
As you can see the \”form action\” is calling \"simple test mail script.asp\" so the processor file must be called in the same way. In the final version of the script I have merged the form and the processor in one file.
The second part of the script is the ASP processor which is setting the diminution variables CDO.Message, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<% 'Dimension variables Dim Mail Dim MailFrom Dim MailTo Dim MailSubject Dim MailContent MailFrom = Request.Form("from") MailTo = Request.Form("to") MailSubject = Request.Form("subject") Set objMessage = CreateObject("CDO.Message") objMessage.Sender = MailFrom objMessage.To = MailTo objMessage.Subject = MailSubject objMessage.TextBody = "This is some sample message text." objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send %> |
You can separate these, but I prefer to keep them into one simple ASP test mail script file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1250"> <title>Mail example</title> </head> <body> <form action="simple_test_mail_script.asp" method="post" name="form" id="form"> Your mail:<br> <input name="from" type="text" id="from"> <br><br> Recipient:<br> <input name="to" type="text" id="to"> <br><br> Subject:<br> <input name="subject" type="text" id="subject"> <br><br> <br> <input type="submit" name="Submit" value="Submit"> </form> <br> <br> </body> </html> <% 'Dimension variables Dim Mail Dim MailFrom Dim MailTo Dim MailSubject Dim MailContent MailFrom = Request.Form("from") MailTo = Request.Form("to") MailSubject = Request.Form("subject") Set objMessage = CreateObject("CDO.Message") objMessage.Sender = MailFrom objMessage.To = MailTo objMessage.Subject = MailSubject objMessage.TextBody = "This is some sample message text." objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send %> |
Just copy the above and paste it into one file called: simple_test_mail_script.asp on our server. You can choose different name, just do not forget to change the form action section with the name you have chosen for your ASP mail script.
Tags
Filed Under: Windows 2003 Server
About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.
Hi Sir. The cdont script is working great! – but when I start it for a first time it gives an error which is confusing my tests when I offer them to the customers. The error message is:
CDO.Message.1 error ‘8004020d’
At least one of the From or Sender fields is required, and neither was found.
/simple_test_mail_script.asp, line 60
Is there a way to remove this error?
Hi Roopali. The error appears, because the cdont test mail script is calling itself, but there are no values yet.
If you want to avoid this error, you have to separate the script as I’ve present it into the first two script boxes. Then the form will not send the request before filling the required test message fields.
I have the same error as Rene. So if I want to avoid this error I have to separate the scripts, but that is not working for me.
I forgot to tell that it gives me an error which says something like the CDONTS is missing.
It is explained in the tutorial. Just make sure you have the correct file name set in the first script calling the CDONTS one
I need aspX test mail script. If I try this one in aspx file, it returns bunch of errors