Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get this error when debug..

An unhandled exception of type 'System.FormatException' occurred in System.dll

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

And this is my code..
VB
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim smtpServer As New SmtpClient()
        Dim mail As New MailMessage()
        smtpServer.Credentials = New Net.NetworkCredential(TextBox15.Text, TextBox16.Text)
        smtpServer.Port = 587
        smtpServer.Host = "smtp.gmail.com"
        smtpServer.EnableSsl = True
        mail = New MailMessage()
        mail.From = New MailAddress(TextBox18.Text)
        mail.To.Add(TextBox17.Text)
        mail.Subject = TextBox19.Text
        mail.Body = TextBox20.Text
        smtpServer.Send(mail)
        MsgBox("Mail Sent!", MsgBoxStyle.OkOnly, "Sent")
    End Sub
End Class
Posted
Updated 30-Mar-15 13:14pm
v3
Comments
phil.o 30-Mar-15 19:15pm    
"The specified string is not in the form required for an e-mail address."
Isn't it self explanatory? You should validate that e-mail addresses in your textboxes are valid ones.
rafizan46 30-Mar-15 19:23pm    
give me an example please :(
phil.o 30-Mar-15 19:24pm    
An example of what? Of a valid e-mail address?
rafizan46 30-Mar-15 19:27pm    
no.. where should i put that valid email adress.. sorry.. im still new.. :(

1 solution

You can check this link out for how to validate an email address.
How to: Verify that Strings Are in Valid Email Format[^]

Use this on TextBox17.Text and TextBox18.Text

And just as a note, it is a good idea to use descriptive names of your variables.
The default names will make you confused later on.
 
Share this answer
 

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