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:
The exception occurs with, the custom error message shows up.
I thank all you experts in advance.
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
I thank all you experts in advance.
Last edited by a moderator: