I have spent all weekend trying to make my simple form mail WORK. And now, much forum hunting and Go Daddy calling later, I want to post what I have learned, hoping to save another newbie a loooooong weekend. So here goes:
1) If you don't have one already, create an e-mail account at Go Daddy. It will take about 15 minutes to become active. Write down your user id and password, then forge ahead with the rest of this. It will take you less than an hour, depending on how detailed your form is.
2) Create your form in MS VWD 2005 X ed using the Wizard tool, per the 13-minute video and free code provided at:
http://msdn.microsoft.com/asp.net/learning/learn/newtodevelopment/Your generic code behind page looks like this, and **needs these changes**:
Imports System.Net.Mail
Partial Class _filename**enter the file name you gave to your form, no .aspx at the end, then confirm at the top of your form that it has this page's correct name**
Inherits System.Web.UI.Page
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If txtComments.Text.Length > 10 Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
**I blew the sub above away; it was easier to just set the "maximum length" restriction for my testbox and add "100 words max" to the field description**
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
SendMail(txtEmail.Text, txtComments.Text)**list ALL of the field names on you form here that you want sent to your e-mail when the form posts. You can list more than two! Just check that the format is right for each field and you are spelling the fields identically to how they appear in your form**
End Sub
Private Sub SendMail(ByVal from As String, ByVal body As String)**This is where you can specify more form fields to return to you, by adding "ByVal Body1 As String, ByVal Body2 As String, etc., up through the number of additional fields you want returned in the e-mail. You will get an error as soon as you add one Body# too many!**
Dim mailServerName As String = "SMTP.MyDomain.com"
**For Go Daddy, replace SMTP.MyDomain.com with smtpout.secureserver.net**
Dim message As MailMessage = New MailMessage(from, "scott@vertigosoftware.com", "feedback", body)
**This is the long one! Replace "scott@vertigosoftware.com" with your Go Daddy e-mail account. Replace "feedback" with the header you want to appear for the e-mail. Then replace body with your formatted string. For example:**Dim message As MailMessage = New MailMessage(from, "you@yourgodaddysitename.com", "This is the Subject", "Email:" + txtEmail.Text + Chr(13) & Chr(10) + "FirstName:" + txtFirstName.Text + Chr(13) & Chr(10) + "LastName:" + txtLastName.Text) will send an e-mail to your Go Daddy e-mail address, with This is the Subject as the header, and a body that looks like this:E-Mail:Email entered on formFirstName:first name entered on formLastName:last name entered on formThat's because Chr(13) & Chr(10) is the command for a Windows hard return.Dim mailClient As SmtpClient = New SmtpClient**a line is missing here. Add:mailClient.Port = 25**Go Daddy has multiple ports. See if this port # works, or call Go Daddy to get additional port info.mailClient.Host = mailServerName
mailClient.Send(message)
message.Dispose()
End Sub
3) Update your web.config file in the system.net section to reflect Go Daddy's smtp info and your user authentication:
<system.net>
<mailSettings>
<smtp from="you@yourgodaddysite.com">
<network host="smtpout.secureserver.net" password="your_e-mail_password" userName="you@yourgodaddysite.com" />
</smtp>
</mailSettings>
</system.net>You should have a working form at this point - I hope! I sent Go Daddy the same links and mentioned what proprietary info they had to give to someone from the first call (rather than the third call, as in my case), so I hope this puts an end to frustrated newbies. Happy FormMailing!
![]() |
0 |
![]() |
Well done! And more so for taking the time to help your peers.
Some quick tips.
Chr(10) & chr(13) are the ASCII Codes for Carriage Return and Line Feed and are not windows specifc.
The best way to embed control chars is controlchars.crlf - try this out to view the other control characters available (Tab etc).
In your message text you are using + or & to concatenate strings. In VB.Net use & for string concatenation.
Dim message As MailMessage = New MailMessage(from, "you@yourgodaddysitename.com", "This is the Subject", "Email:" + txtEmail.Text + Chr(13) & Chr(10) + "FirstName:" + txtFirstName.Text + Chr(13) & Chr(10) + "LastName:" + txtLastName.Text) will send an e-mail to your Go Daddy e-mail address, with This is the Subject as the header, and a body that looks like this:
becomes
Dim message As MailMessage = New MailMessage(from, "you@yourgodaddysitename.com", "This is the Subject", "Email:" & txtEmail.Text & controlchars.crlf & "FirstName:" & txtFirstName.Text & controlchars.crlf & "LastName:" & txtLastName.Text) will send an e-mail to your Go Daddy e-mail address, with This is the Subject as the header, and a body that looks like this:
Happy coding.
Rgds,
Martin.
For the benefit of all users please mark any post answers as appropriate.
![]() |
0 |
![]() |
"Chr(10) & chr(13) are the ASCII Codes for Carriage Return and Line Feed and are not windows specifc."
Strictly speaking 10 and 13 are appropriate the ASCII codes.
Rgds,
Martin.
For the benefit of all users please mark any post answers as appropriate.
![]() |
0 |
![]() |
Cool! Will use the embedded characters next - thanks - dma
![]() |
0 |
![]() |