private void btnSend_Click(object sender, EventArgs e) { ++SentEmailId; SentMail mail = new SentMail(txtSubject.Text, txtMessage.Text, DateTimeOffset.Now, SentEmailId, txtTo.Text); WriteMails writeNewMail = new WriteMails(); writeNewMail.SendEmail(mail); Hide(); }
public void SendEmail(SentMail mailAboutToSend) { var message = new MimeMessage(); message.From.Add(new MailboxAddress("*****@*****.**")); message.To.Add(new MailboxAddress(mailAboutToSend.to)); message.Subject = mailAboutToSend.subject; message.Body = new TextPart("plain") { Text = mailAboutToSend.message }; using (var client = new SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.gmail.com", 587, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate("*****@*****.**", "mergeconflict"); client.Send(message); } }