public void OkCommand(object ownerWindow) { MailProviderFactory emailFactory = null; switch (_selectedReceiveConfiguration.Protocol) { case EmailProtocolType.Imap: emailFactory = new ImapProviderFactory(); break; case EmailProtocolType.Pop3: emailFactory = new Pop3ProviderFactory(); break; default: break; } MailConnection connection = emailFactory.CreateConnection(); connection.Host = _selectedReceiveConfiguration.Host; connection.IsSslAuthentication = _selectedReceiveConfiguration.IsSslAuthentication; connection.Port = _selectedReceiveConfiguration.Port; ////connection.Open(); SslMailConnectionDecorator sslMailConnectionDecorator = new SslMailConnectionDecorator(); sslMailConnectionDecorator.MailConnection = connection; sslMailConnectionDecorator.Open(); MailClient client = emailFactory.CreateClient(); client.Authenticate(new MailUserInfo() { Email = _login, Password = _securePassword }); new MainWindow() { DataContext = new MainWindowVM(client) }.Show(); ((Window)ownerWindow).Close(); }