public void TestTwoClients() { using (var imapClient = new ImapClient()) { imapClient.ServerCertificateValidationCallback = (s, c, ch, e) => true; imapClient.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect); imapClient.AuthenticationMechanisms.Remove(Constant.GoogleOAuth); imapClient.Authenticate(Constant.GoogleUserName, Constant.GenericPassword); Console.WriteLine(imapClient.IsAuthenticated); using (SmtpClient smtpClient = new MailKit.Net.Smtp.SmtpClient()) { smtpClient.ServerCertificateValidationCallback = (s, c, h, e) => true; smtpClient.Connect("smtp.gmail.com", 465, true); smtpClient.AuthenticationMechanisms.Remove(Constant.GoogleOAuth); smtpClient.Authenticate(Constant.GoogleUserName, Constant.GenericPassword); Console.WriteLine(smtpClient.IsAuthenticated); smtpClient.Disconnect(true); } imapClient.Disconnect(true); } }
public void SendEmail() { List <MailboxAddress> emailNoticationList = new List <MailboxAddress>(); emailNoticationList.Add(new MailboxAddress("*****@*****.**")); emailNoticationList.Add(new MailboxAddress("*****@*****.**")); emailNoticationList.Add(new MailboxAddress("*****@*****.**")); using (SmtpClient client = new MailKit.Net.Smtp.SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.gmail.com", 465, true); client.AuthenticationMechanisms.Remove(Constant.GoogleOAuth); client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword); foreach (var mailboxAddress in emailNoticationList) { MimeMessage message = new MimeMessage(); message.From.Add(new MailboxAddress("Rally Integration", Constant.GoogleUserName)); message.To.Add(mailboxAddress); message.Subject = "SMTP: Test Email"; message.Body = new TextPart("plain") { Text = "Hello Test Email" }; client.Send(message); } client.Disconnect(true); Console.WriteLine("Sent"); } }