WebForm - Send Email Please Help

Newbie81

Member
Joined
Nov 7, 2006
Messages
12
Programming Experience
Beginner
Hello All,
I have a simple webform that the user fills in, they enter their email and queries. Once they press the submit button, I want to receive an email to my email account.
I am using 1.0 framework, and I am using my hosts smtp send email.
Here is my code:
VB.NET:
PrivateSub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
 Handles btnSubmit.Click
If Page.IsValid Then
 Dim MailMessage As New MailMessage
 Dim sBody As String
 Dim Title As String = ddlTitle.SelectedValue
 Dim Name As String = txtName.Text
 Dim Tel As String = txtTelephone.Text
 Dim EmailAddress As String = txtEmail.Text
 Dim Enquiry As String = txtEnquiry.Text
 Dim Body
 Body = Body & "Title: " & Title & vbCrLf
 Body = Body & "Name: " & Name & vbCrLf
 Body = Body & "Telephone: " & Tel & vbCrLf
 Body = Body & "EmailAddress: " & EmailAddress & vbCrLf
 Body = Body & "Enquiry: " & Enquiry & vbCrLf
 With MailMessage
   .From = EmailAddress
   .To = "[EMAIL="email@crystalcleaningco.co.uk"]email@crystalcleaningco.co.uk[/EMAIL]"
   .Subject = "CrystalCleaning Website Enquiry"
   .Body = Body
   .Fields("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]") = "intmail.atlas.pipex.net" (host smtp server)
   .Fields("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]") = 25
   .Fields("[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]") = 2
   .Fields("[URL]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate[/URL]") = 1
   .Fields("[URL]http://schemas.microsoft.com/cdo/configuration/sendusername[/URL]") = "my email username"
   .Fields("[URL]http://schemas.microsoft.com/cdo/configuration/sendpassword[/URL]") = "my password"
   Try
     SmtpMail.Send(MailMessage)
     lblMessage.Text = ddlTitle.SelectedItem.Text + txtName.Text & ", Thank for submitting your Enquiry. We will Contact you soon."
     Catch ex As Exception
     lblMessage.Text = "An Error has occured. Please try again later."
   End Try
 End With
End If
End Sub
The exception occurs with, the custom error message shows up.

I thank all you experts in advance.
 
Last edited by a moderator:
Hello, Thank you for the reply. I actually did try to show the error on the label message, but when I run it, and press the submit button, no exception shows up. But when I check my email, there is no email, meaning it didnt work.
 
Try sending an email message from say hotmail to your local server, the one that you use to send smtp out. This way you could verify if your smtp server actually works. If the message appears in Inetpub\mailroot\Mailbox, I think it was, then you are fine. Otherwise, what OS are you using?
 
Hell all, thank you for the replies. Once I uploaded online, it worked fine....The key was setting the smtp to the hosting company that I was using.

Thank you for your help
 
Back
Top