Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send the password by email when the user requests it in forgot password but I am getting an error.

The specified string is not in the form required for an e-mail address.

I tried to put different syntax but I am unable to solve it.
here's the code:


Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim mailtxt As String = mail_txt.Text
Dim numtxt As String = num_txt.Text
Dim sbmail As New StringBuilder
Dim conn As New MySqlConnection("DataBase=sample;Data source=localhost;username=root;password=sa;")
Dim str As String
str = " select * from user_details where email='" + mail_txt.Text + "' and secno='" + num_txt.Text + "' "
Dim cmd As New MySqlCommand(str, conn)
conn.Open()
Dim dr As MySqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim userID As New Integer
If dr.HasRows Then
Dim dbuname As String = dr("user_name").ToString()
Dim dbpassword As String = dr("user_password").ToString()
Dim dbemail As String = dr("email").ToString()
Dim dbnum As String = dr("secno").ToString()

If ((String.Equals(mailtxt, dbemail)) And (String.Equals(numtxt, dbnum))) Then
Dim MailMsg As New MailMessage()
MailMsg.To.Add("mail_txt.Text".ToString())
MailMsg.From = New MailAddress("anub96@gmail.com")
MailMsg.Subject = "Retrive Your Password"
Dim body As String = ("username=" + dbuname + " " + "password=" + dbpassword + " " + "mailid=" + dbemail + " ")
MailMsg.Body = body.ToString()
MailMsg.IsBodyHtml = True
Dim SmtpMail As New SmtpClient()
SmtpMail.Host = "smtp.gmail.com"
SmtpMail.Port = 587
SmtpMail.Credentials = New System.Net.NetworkCredential("anub96", "capricorn")
SmtpMail.EnableSsl = True
SmtpMail.Send(MailMsg)
End If

Else
Response.Write("<script> Window.Alert('Invalid User')</script>")
End If
End Sub
Posted
Updated 11-Aug-10 13:38pm
v2
Comments
Scubapro 11-Aug-10 8:30am    
You'll probably have to change your gmail password now!
anupama962010 11-Aug-10 8:34am    
i gave the wrong password
Scubapro 11-Aug-10 9:50am    
Well, thank heaven for that!
Dalek Dave 11-Aug-10 19:39pm    
Minor Edit for Grammar.

1 solution

Surely it's this line

MailMsg.To.Add("mail_txt.Text".ToString())


That needs to be something like
MailMsg.To.Add("user.name@somedomain.com"));
 
Share this answer
 
Comments
tiggerc 11-Aug-10 9:40am    
looking at it, i would have said MailMsg.To.Add(mail_txt.Text.ToString()) as it looks like he is trying to reference a text box but enclosing the textbox name in quotes.
Dylan Morley 11-Aug-10 9:44am    
Yeah that happens in the first line, so just use the variable there - MailMsg.To.Add(mailtxt), no need for anything else.

I was pointing out that the error being thrown was because of the string being added ("mail_txt.Text") which needs to be in mail address format ("user.name@somedomain.com")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900