FormMail - Using CDOSYS on GoDaddy

Form mail provides a way for people to contact you without making your email address visible to spammers. There are several types of server programs

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 IIS 6 at GoDaddy. (Or the information in the control panel - which said I was using IIS 6 - did not match what was provided.)

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 | CDO.Message Object
CDO_MailForm.asp - objMail.To Server Configuration Spam Protection
Advantages | Converting from CDONTS to CDOSYS


GoDaddy's example script

GoDaddy provides the following example CDOSYS script. Unfortunately, it does not indicate how to get data from your form.


CDO.Message Object

CDO.Message is implemented via cdosys.dll, for basic help see - CDO for Windows 2000 - IMessage Interface.

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

To imbed a double quote, use two double quotes.

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.

I have not verified that the same rules apply with CDOSYS because GoDaddy has an additional rule. As a result, you can not allow your users to enter an objMail.From value .. even if you do fully validate it. The solution is to use any dummy address you want (GoDaddy says that it must be from your url, but my tests indicate that any address not in the above list will work) and to place the user's address in the ReplyTo field. Using the Reply button in Thunderbird (an email program) causes the ReplyTo value to be placed in the new email's To address .. but only when it is formatted correctly. When the return address has certain errors, the To field is left blank. As a result, I also place a copy of the user's email address in the body of the text .. just in case.

By the way, the property names are not case sensitive. Both ReplyTo and REplyTo work.


CDO_MailForm.asp

This is the file I wrote ... with the to address obscured (to reduce spam) - the from address is just a dummy address that is correctly formatted.


objMail.To

The address the email is sent to should always be read from the server ... never from the html form. In this example, it is hard coded - be sure to change this when you use this code.


Server Configuration

With GoDaddy shared hosting, the mail server is on one system, and your web pages are on another. Therefore, to send formmail via CDOSYS, your script needs to indicate where the mail server is located. While this help file only sets 2 parameters - sendusing and smtpserver - the following code has 4 since that is what was in the example file I received from GoDaddy support. Similar code can be used to set a username and password, but those are not needed as long as your site is hosted at GoDaddy.


Spam Protection

These lines are used to reduce the probability of getting spam via this script. You should change the field name and the test string.

The following all produce - HTTP 500 - Internal server error

Therefore I decided to use the following which produces - Page Not Found

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

There are several reasons that I prefer CDONTS_MailForm.asp over gdform.asp The availability of CDONTS was the first good reason I'd seen for picking Windows over Linux for a web server. Now that GoDaddy no longer supports that, I have changed to CDOSYS.

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

When my old email address died, I had to modify the scripts to use another. Simple - just edit one line (the objMail.To address) in the existing CDONTS based *.asp file and I would be done.

Well .. that was the plan. It did not work.

As of 03-01-12, the GoDaddy CDONTS help page said

According to GoDaddy, my site was still using IIS 6.0 .. but CDONTS no longer worked. I couldn't help but wonder. At Using Windows Hosting Form Mailers, the expanded gdform.asp help said Well, the last form mail from my site was dated 10-12-2011 .. so that couldn't be the problem.

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

At GoDaddy, the bigest change between the CDONTS script and CDOSYS is the need to specify the server configuration. As a result, most of the CDOSYS examples found on the web will not work with GoDaddy. I am certain that this was added for security reasons. This information does not appear on most sites covering the two methods and it is very difficult to find on the GoDaddy site.

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

Get it? CDO is implemented in cdosys.dll. All the Microsoft help is indexed under CDOSYS .. and GoDaddy places their help under CDO. No wonder I had to request help .. twice!

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
URL: http:// mc-computing.com / ISPs / FormMail_CDOSYS.html