public void sendMail(string username, string password, string recipient, string subject, string body) { System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(txtTo.Text); System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(txtFrom.Text); System.Net.Mail.MailMessage MyMail = new System.Net.Mail.MailMessage(fromAddress, toAddress); System.Net.Mail.SmtpClient mClient = new System.Net.Mail.SmtpClient(); mClient.Port = 587; MyMail.Body = body; mClient.EnableSsl = true; MyMail.Subject = subject; mClient.UseDefaultCredentials = false; mClient.Credentials = new System.Net.NetworkCredential(username, password); mClient.Host = "smtp.gmail.com; mClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; mClient.Timeout = int.MaxValue; mClient.Send(MyMail); }