Note: |
With Internet Information Server (IIS),
Simple Mail Transfer Protocol (SMTP) service must be enabled
and configured in order to use either of these. CDONTS is not available with IIS 7.
After Nov 2011, CDONTS was no longer available on |
This page is related to sending form mail using CDOSYS with a GoDaddy account, but most of this data can be used at other ISP's.
GoDaddy's example script
<% sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing" smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver" ' Set the mail server configuration Set objConfig=CreateObject("CDO.Configuration") objConfig.Fields.Item(sendUrl)=2 ' cdoSendUsingPort objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net" objConfig.Fields.Update ' Create and send the mail Set objMail=CreateObject("CDO.Message") ' Use the config object created above Set objMail.Configuration=objConfig objMail.From="sender@coolexample.com" objMail.ReplyTo="sender@coolexample.com" objMail.To="recipient@coolexample.com" objMail.Subject="subject" objMail.TextBody="body" objMail.Send %> |
CDO.Message Object
The properties to, cc, and bcc each allow you to include one or more email addresses - multiple addresses are separated by commas. (With CDONTS, they were separated by semicolons.)
objMail.To = "useraddress@example.com" objMail.To = "user1@example.com,user2@example.com,user3@example.com" objMail.To = """User 1"" <user1@example.com>, user2@example.com,user3@example.com" |
With CDONTS, if the From address is badly formed, then the mail does not go ... and there is no error. Your code MUST validate the address or use a dummy address.
objMail.From = "useraddress@example.com" ' good objMail.From = "Just any text" ' fails - not a valid address |
Here’s a list of email address domain names we don’t let our customers use as the From value of their forms:
|
from = request.form("FromAddress") ' optional field if from <> "" then body = "From: " & from & vbCRLF & vbCRLF & body objMail.From = "dummy_address@xx.com" ' too hard to validate objMail.ReplyTo = from ' can be blank or any string, not validated |
By the way, the property names are not case sensitive. Both ReplyTo and REplyTo work.
CDO_MailForm.asp
<% ' CDOSYS_MailForm_mc.asp ' ' 03-02-12 started - by R Clemenzi ' based on data from GoDaddy ' ' This only works with "post" html forms ' read form variables from = request.form("FromAddress")' optional field body = request.form("body") ' what the person types subject = request.form("subject") ' from a hidden field redirect = request.form("redirect") ' from a hidden field from_url = request.form("a_url") ' from a hidden field ref_url = request.form("ref_url") ' from a hidden field value = request.form("val") ' from a hidden field - spam protection if value <> "pen" then Response.redirect "404_NotFound.html" ' quit if invalid submission if subject = "" then subject = "[mc-computing] null subject" ' the subject may contain %20 where spaces should be subject = replace(subject, "%20", " ") ' this replaces all occurrences of the string if from <> "" then body = "From: " & from & vbCRLF & vbCRLF & body body = body & vbCRLF & vbCRLF & "url: " & ref_url ' send the email If Len(body) > 0 Then Dim myCon, objMail Set objMail = Server.CreateObject("CDO.Message") Set myCon = Server.CreateObject("CDO.Configuration") 'Modify the smtp server for the smtp server that your hosting uses ' (localhost for dedicated, relay-hosting for shared) myCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net" myCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 myCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 myCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 myCon.Fields.Update Set objMail.Configuration = myCon objMail.To = "someone@anywhere.com" ' always hard code this to hide from spammers objMail.From = "dummy_address@xx.com" ' too hard to validate objMail.ReplyTo = from ' can be blank or any string, not validated objMail.Subject = subject ' objMail.HTMLBody = body ' I don't use this, included as an example only objMail.TextBody = body objMail.Send 'Close the server mail object - these are required Set objMail = Nothing Set myCon = Nothing End If if redirect = "" then redirect = "Feedback_Done.html" Response.redirect redirect ' next page the user sees %> |
objMail.To
objMail.To = "someone@anywhere.com" ' always hard code this to hide from spammers |
Server Configuration
Dim myCon, objMail Set objMail = Server.CreateObject("CDO.Message") Set myCon = Server.CreateObject("CDO.Configuration") 'Modify the smtp server for the smtp server that your hosting uses ' (localhost for dedicated, relay-hosting for shared) myCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net" myCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 myCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 myCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 myCon.Fields.Update Set objMail.Configuration = myCon |
Spam Protection
value = request.form("val") ' from a hidden field - spam protection if value <> "pen" then Response.redirect "404_NotFound.html" ' quit if invalid submission |
The following all produce - HTTP 500 - Internal server error
if value <> "pen" then return if value <> "pen" then request.end if value <> "pen" then exit if value <> "pen" then exit sub if value <> "pen" then Server.Transfer "404_NotFound.html" |
Therefore I decided to use the following which produces - Page Not Found
if value <> "pen" then Response.redirect "404_NotFound.html" |
In addition, you should use a unique filename for the script itself - perhaps, just add your initials - so that it is harder for spammers to hit lots of accounts.
Advantages
<textarea name="body" cols="70" rows="20"></textarea> |
Unfortunately, using CDOSYS, there is now a significant delay between submitting the form and when the text appears in my mail reader. Using CDONTS, the delay was usually less than 10 seconds. I am guessing here, but one possibility is that CDONTS was communicating directly with IIS and that CDOSYS causes the email file to be written to a directory which is checked about once every 5 minutes. The other (obvious) possibility is that both methods cause files to be written in some directory and that IIS is configured to set the delay between reads. Either way, this is not a big deal, but the longer wait makes debug and test much more frustrating.
Converting from CDONTS to CDOSYS
Well .. that was the plan. It did not work.
As of 03-01-12, the GoDaddy CDONTS help page said
NOTE: This script will not work on Windows® hosting plans running IIS 7. |
WARNING: As of October 29th, 2008, gdform.asp is no longer offered on Windows shared hosting accounts. If your account does not have gdform.asp, these instructions will not work. |
After a day or so of intense debug, I noticed that all the directories on my site had relatively new timestamps - 11-01-2011. After a bit of investigating, I discovered (via an old email on that date) that GoDaddy had moved my site to a new server. That's what convinced me that the problem was at their end .. and not my problem.
At that point, I wrote an email explaining all the steps I had done and asked them to check their end. Their (canned) reply was that they would not help me with script problems and that I should try a few things that my original email said that I had already tried.
At that point, I replaced my script with the CDONTS example from the GoDaddy help pages (using hardcoded email addresses) and, since it also did not work, sent a follow-up email asking for help again. This time, they replied with a new script that worked .. very similar to the one presented above, but more complete - it BOTH created the form AND sent the email.
Based on that script, I eventually found the help page that explained how to implement CDO - it took another day or so (while writing this page) to realize that what GoDaddy called CDO was the same as what Microsoft calls CDOSYS.
If their help pages were any good, I would have found this myself. On the other hand, out of several thousand customers, there are probably only a handful that prefer to have their own scripts. And, in the final analysis, the GoDaddy support staff did fix my problem. Unfortunately, it is highly likely that form mail from my site was down for just over 4 months without me knowing about it. (Note - if you are not getting emails from your site, but sure to check the forms at least once a month. The last mail from my form was about 2 weeks before the server change.)
Server Configuration
For instance, these lines were not included in the CDOSYS C# help files which can be found via Which form mailers can I use with my Windows hosting account?
After several days of trouble shooting, I made a help request to GoDaddy because I was using their examples and nothing was working. After the first request, I got a response basically saying that I needed to try everything I had already documented in the first email. After a second request, they admitted that the "problem" was at their end and they provided a script that worked.
Silly me - I had been searching for help using CDOSYS (the official Microsoft replacement for CDONTS) and the usable help was located at
The help files only configure 2 parameters - sendusing and smtpserver.
The example file provided by GoDaddy contained 4. (See the code above.)
Author: Robert Clemenzi