Kauten Effects’s Blog

March 18, 2008

CDOSYS vs. GDForm.asp: GoDaddy’s Mail-Relay Alternative

Filed under: GoDaddy — Tags: , , , , , , , , , , — kauteneffects @ 8:47 pm

One thing I have come across time and time again are fellow developers who are completely perplexed by the GoDaddy GDform.asp form mailer. What they often times do not realize is that this is not the only method available to them; GoDaddy also allows for the use of the CDONTS and CDOSYS functionalities. Proof of this can be found in the GoDaddy help knowledge base found here: http://help.godaddy.com/article/1485

The CDOSYS functionality is what I am going to focus on here as it is what I personally use and have had amazing results with. It uses the System.Net.Mail namespace and can be used with all of the Windows hosting accounts on the GoDaddy network. Certain hosting accounts however do have some limitations as to how many messages can go out in a day, which I will discuss later in this post. If you want to check out the GoDaddy help knowledge base article on using CDOSYS functionalities feel free to check it out at the following URL, however rest assured that I am going to simplify it for you a bit: http://help.godaddy.com/article/1073

The example I am going to show you will be using the VB.Net code system which as we all know in the .Net world, means you can easily interpret it into whichever .Net language you are using. First a little background though, my example uses the CDOSYS functionality in a relatively simplified form other than the fact that I have moved it out to a class file in all of my projects so that I may globally reference it from any page in my project without having to write to code in multiple places.

Now on to the example:

1    Imports Microsoft.VisualBasic
2    Imports System.Net.Mail
3    
4    Public Class cdosys
5        Public Function SendMail(ByVal Sender As String, ByVal Recipient As String) As Boolean
6            Try
7                Dim tstMail As MailMessage = New System.Net.Mail.MailMessage(Sender, Recipient)
8                tstMail.Subject = “CDOSYS Test Email: ” & Now().ToString
9                tstMail.Body = “<html><body><center>Here is your test email.</center></body></html>”
10               tstMail.BodyEncoding = Encoding.ASCII
11               tstMail.IsBodyHtml = True
12               ‘Declare Mail Client
13               Dim SMTPServer As String = “relay-hosting.secureserver.net”
14               Dim sClient As SmtpClient = New SmtpClient(SMTPServer)
15               ‘Send Email
16               sClient.Send(tstMail)
17               ‘Release Objects
18               tstMail = Nothing
19               sClient = Nothing
20               Return True
21           Catch ex As Exception
22               Return False
23           End Try
24       End Function
25   End Class

Now that you have seen what we are working with, let me break it down a little bit. First things first you need to make sure you import the System.Net.Mail namespace into your project. You can either do it as I have done on line 2 of the example, or include it in your project’s web.config file. It really is up to you. Next up on line 5 we have the function I have defined to get us rolling with the email process. I have the function set to return a boolean value so that the page calling the function will know whether there were errors or not and can then handle it appropriately. Aside from that I have specified the sender and the recipient as the two ByVals. You can of course use more if you wish to enable a higher level of customization, but that is all up to your imagination as mine here is just a simple example.

Next up we have to create our MailMessage object as seen on line 7 of my example. There are about four different options here with creating a new MailMessage object such as what I have done here including the sender and recipient in the creation of the object. Alternatively you could create the object with the sender, recipient, subject, and body content all in one line. For organization and cleanliness however, I chose to leave that up to a few different processes within the example. Once we have successfully declared our MailMessage variable and created the object we move on to some of the options.

Lins 8 and 9 show how simple it is to specify the subject and body contents of the mail message. There really isn’t much to explain here other that you know have the ability to add HTML content to the body. You can also do something similar to what I have done with the subject and included the current time. I find this allows for me to keep an eye on when the mail object is created and when it actually arrives. So far I have had great results with the email arriving within 3 minutes of sending it. Moving on lets take a look at lines 10 and 11.

Both of these lines handle some of the settings pertaining to the body content. First we set the body encoding; not something you always have to do, but it never hurts. Then we move on to inform the system that the body content will actually be using an HTML format rather than just plain text. Again, pretty straight forward and simple to understand. What comes next may not make as much sense, but still have no fear.

Lines 13 and 14 are we we actually specify the GoDaddy SMTP relay’s server address, and create out object to actually mail the MailMessage object we created before. In order to get these messages off of the GoDaddy network you must specify “relay-hosting.secureserver.net” as the server of choice here. Next we create the SmtpClient object and attach it to our variable. Fortunately this process is very simple and pretty self explanatory, it is just a matter of making sure you get the server address correct.

Line 16 is what finally sends the mail message we have been working with thus far. Once we execute this then we are done with our whole mailing process and all that is left is a little cleanup. Lines 18 and 19 take care of this for us. Though there is some uncertainty as to whether this is truly required or not, it absolutely never hurts. Line 20 returns the success message to our calling page and alas we are all done here and can move on to bigger and better things.

Before I let you go though there are some things to clear up which I have often seen people confused with and of course referring back to earlier, explaining the limitations of this method. One thing I always see people ask is whether you have to include any form of credentials with this method. You in fact do not. Because it is all local to the GoDaddy network the relaying server is aware that the request is coming for a GoDaddy hosting server and as such knows it is not an outside source trying to port an open relay through them. Secondly, there are no references that need to be made to any of the global godaddy.web.config files. Since your project should presumably already be using .Net 2.0 and have the proper configurations set to make the directory the root project, then all that your project needs to see is the web.config file you have included with it. Lastly, this relay server has nothing to do with the mail relays that you are allowed for the email addresses you configure for your domain. Those simply apply only to the SMTP interactions between your email account there and the mail client you choose to use to access your emails in place of the GoDaddy WebMail system.

Now for the fun part; the limitations. If you are on a shared hosting plan there is no reference as to what sorts of limitations are in place for how many emails can be sent using the relay. The way I see it, since GoDaddy does not require any credentials they simply check to make sure it is their own hosting server making the request and because there can be thousands of sites hosted on your one shared hosting server it would be more difficult for them to determine where the request was originating versus just letting shared hosting servers have unlimited access to the relay server. However if you are on a dedicated hosting plan, they are aware of how many posts you are making to the relay server so just be aware that you are limited to 1000 outbound mails a day. Proof of this can be found in the GoDaddy help knowledge base article found here: http://help.godaddy.com/article/1167

Hopefully by now you have a decent understanding of just what all you can do with the GoDaddy system and also understand that the GDform.asp form mailer is not your only option. If you need a little extra help, feel free to let me know and I will see what I can do. I just don’t want to see any more people leaving the GoDaddy network over something as simple as a form mailer.

Thank you,

Geoff Kauten
www.KautenEffects.com

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.