· 9 years ago · Dec 07, 2016, 05:34 PM
1 try
2 {
3 if (!textBox1.Text.Contains("gmail.com"))
4 {
5 MessageBox.Show("You need to provide an email @gmail.com");
6 return;
7 }
8 button1.Enabled = false;
9 MailMessage message = new MailMessage();
10 message.From = new MailAddress(textbox4.Text);
11 message.Subject = textBox2.Text;
12 message.Body = textBox3.Text;
13 foreach (string s in textBox5.Text.Split(';'))
14 message.To.Add(s);
15 SmtpClient client = new SmtpClient();
16 client.Credentials = new NetworkCredential(textbox4.Text, textBox5.Text);
17 client.Host = "smtp.gmail.com";
18 client.Port = 587;
19 client.EnableSsl = true;
20 client.Send(message);
21 }
22 catch
23 {
24 MessageBox.Show("There was an error sending the message please make sure you entered all the right information and have a active connection to the internet");
25 }
26 finally
27 {
28 button1.Enabled = true;
29 }
30 }