Hi
Try this code
Try
'(1) Create the MailMessage instance
Dim mm As New MailMessage(FromEmailAddress, ToEmailAddress)
'(2) Assign the MailMessage's properties
mm.Subject = "Test Email... "
mm.Body = "This is a test message..."
mm.IsBodyHtml = False
'(3) Create the SmtpClient object
Dim smtp As New SmtpClient
'Set the SMTP settings...
smtp.Host = Hostname.Text
If Not String.IsNullOrEmpty(Port.Text) Then
smtp.Port = Convert.ToInt32(Port.Text)
End If
If Not String.IsNullOrEmpty(Username.Text) Then
smtp.Credentials = New NetworkCredential(Username.Text, Password.Text)
End If
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
'Display a client-side popup, explaining that the email has been sent
ClientScript.RegisterStartupScript(Me.GetType(), "HiMom!", String.Format("alert('An test email has successfully been sent to {0}');", ToAddress.Replace("'", "\'")), True)
Catch smtpEx As SmtpException
'A problem occurred when sending the email message
ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
'Some other problem occurred
ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
Mark as solve if it helps you