Hello
I am aiming to have an aspx file with a TextBox for the user to type in his email. When I leave the field blank, and press
'Submit', I get: "A password reset link has been sent to your email address"
Why don't I get the error message:
If UserEmail.Text = "" Then
Label1.Text = "Please complete the required fields"
Label1.Visible = True
End If
as indicated in my code, please?
In fact, when I do type in an email address - an erroneous one - I still get the same message (the message is sent: I can see it in a folder on my C drive).
Here is my code:
Protected Sub btnPassSend_Click(sender As Object, e As EventArgs) Handles btnPassSend.Click
Dim conn As New OleDbConnection
Dim OleDbConnection As New OleDbConnection
Dim cmd As New OleDbCommand
'Check if email field is empty
If UserEmail.Text = "" Then
Label1.Text = "Please complete the required fields"
Label1.Visible = True
End If
' Connect to Access and open
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|students.mdb;"
conn.Open()
'Check the user's email address in the strEmail column in Access corresponds to that entered by the user in
'the TextBox whose ID is "UserEmail"
cmd = New OleDbCommand("SELECT strEmail FROM university WHERE strEmail=@strEmail", conn)
cmd.Parameters.AddWithValue("@strEmail", UserEmail.Text)
cmd.Connection = conn
cmd.ExecuteNonQuery()
'close Access connection
conn.Close()
Try
Dim SMTPMail As New System.Net.Mail.MailMessage()
SMTPMail.From = New MailAddress("John Doe <info@johndoe.net>") 'This is the Webmaster
SMTPMail.[To].Add("you@yourcompany.com") 'This is the user
SMTPMail.Bcc.Add("Webmaster@mySite.com")
SMTPMail.Subject = "Link to reset your password"
SMTPMail.SubjectEncoding = System.Text.Encoding.UTF8
SMTPMail.IsBodyHtml = True 'IsBodyHtml is true because HTML tags are included
SMTPMail.BodyEncoding = System.Text.Encoding.UTF8
SMTPMail.Body = "Hello<br><br>Please click <a href='http://usingasp.net/reset_pwd.aspx'>here</a> to reset your password.<br><br>Regards<br><br>Dima Dayoub"
Dim dirInfo As New DirectoryInfo("C:\TestEmails")
If Not dirInfo.Exists Then
Directory.CreateDirectory("C:\TestEmails")
End If
Dim SMTP As New SmtpClient()
SMTP.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory
SMTP.PickupDirectoryLocation = "C:\TestEmails"
Dim mailAuthenticaion As New System.Net.NetworkCredential("info@mySite.com ", "SMTP server password")
Dim SMTPserver As New System.Net.Mail.SmtpClient("smtp.mail.server", 25)
SMTPserver.EnableSsl = True
SMTPserver.Credentials = mailAuthenticaion
SMTP.Send(SMTPMail)
Label1.Text = "A password reset link has been sent to your email address"
Label1.Visible = True
Catch ex As Exception
Label1.Text = "Error sending message. Please try again"
Label1.Visible = False
End Try
End Sub
Thanks for any help.