Hello I am using visual c# 2010 and I am trying to send an email with gmail but I get an exception when I try to send the email at:
MailMessage mail = new MailMessage(From.Text, To.Text, Subject.Text , richTextBox2.Text);
From.Text
, To.Text
, Subject.Text
, richTextBox2.Text
are all text boxes with the information inside.
Here is the whole mail segment I am using:
SmtpClient client = new SmtpClient(smtp.Text);
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential(Username.Text, Password.Text);
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("mail sent");
The exception is: FormatException was Unhanded
The exception description is :The specified string is not in the form required for an e-mail address
And I have tried just filling the information out like so :
MailMessage mail = new MailMessage("you@gmail.com", "me@gmail.com", "hello" , body.Text);
//example //example
But I still get an exception. What am I doing wrong ?
Here are the values :
To.Text = "gerardcrafting@gmail.com";
smtp.Text = "smtp.gmail.com";
Password.Text = "Password";
Username.Text = "staff.gerardcrafting.gmail.com";
Subject.Text = textBox1.Text + "Banned" + richTextBox4.Text;