public void SendMail() { string[] data = MailVisualObjects.SendMailDialog(); if (data != null) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(Credentials[0])); message.To.Add(new MailboxAddress(data[0])); message.Subject = data[1]; message.Body = new TextPart("plain") { Text = data[2] }; 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(Credentials[0], Credentials[1]); client.Send(message); client.Disconnect(true); MessageBox.Show("E-mail sent successfully."); } } }
public string[] ReadCredentials() { string[] credentials; if (File.Exists(pathToFile)) { File.Decrypt(pathToFile); credentials = File.ReadAllLines(pathToFile); File.Encrypt(pathToFile); return(credentials); } else { credentials = MailVisualObjects.LoginDialog(); } return(credentials); }
public void RefreshMailBox() { lock (this) { idCounter = 0; try { List <Mail> temp = connection.GetMails(); foreach (Mail item in temp) { item.ID = idCounter++; } mailBox = temp; } catch { MessageBox.Show("Invalid credentials. Please try again."); string[] credentials = MailVisualObjects.LoginDialog(); connection.Credentials = credentials; } } }