SmtpTlsStarted Event |
Namespace: MailBee.SmtpMail
using System; using MailBee; using MailBee.SmtpMail; using MailBee.Security; class Sample { // TlsStarted event handler. private static void OnTlsStarted(object sender, TlsStartedEventArgs e) { // This will happen during Hello method execution. Console.WriteLine("TLS/SSL session started."); } // The actual code. static void Main(string[] args) { Smtp mailer = new Smtp(); // Subscribe to TlsStarted event. mailer.TlsStarted += new TlsStartedEventHandler(OnTlsStarted); // Notify MailBee it should start TLS/SSL session when appropriate. // The connection is made to the regular port so that STLS command // will be used to start TLS/SSL session. SmtpServer server = new SmtpServer("smtp.company.com"); server.SslMode = SslStartupMode.UseStartTls; mailer.SmtpServers.Add(server); mailer.Connect(); Console.WriteLine("Connected to the server. Will send greeting now..."); // TLS/SSL negotiation will take place here. Thus, any subseqeunt commands // such as sending user credentials or mail message submission will take // place under secure TLS/SSL layer. // Note: EHLO command will be sent twice: first, before TLS/SSL negotiation; // second, after. This is because capability list presented by EHLO response // can change after TLS negotiation. mailer.Hello(); Console.WriteLine("Hello completed successfully."); // Can send mail, perform login or whatever here. mailer.Disconnect(); } }