I am new to C#. In my verge of learning this language, I made a windows form application application that takes in an email address and a password and sends it to a pre-specified email address. I don't think that I have messed up the data types though I am getting an error The specified string is not in the form required for an e-mail address.
My code is below :
namespace mailTest
{
public partial class Form1 : Form
{
string mailAddress = "lancepreston@gmail.com";
string mailPassword = "123456789";
string SMTP = "smtp.gmail.com";
public Form1()
{
InitializeComponent();
}
private void button_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage(Email.Text, Password.Text); \\ I get the error on this line
SmtpClient client = new SmtpClient(SMTP);
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential(mailAddress,mailPassword);
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("Mail Sent!", "Success", MessageBoxButtons.OK);
}
}
}
Screenshot of my form :