//Ensure login and do something private IMailClient EnsureLogin(Action <MailMsgBase> onMessage = null) { //Connect if (globalClient == null) { globalClient = clientCreator.Invoke(); } if (!globalClient.IsConnected) { globalClient.Connect(settings.Host, settings.Port, settings.EnableSsl); } if (!globalClient.IsAuthenticated) { if (onMessage == null) { globalClient.Login(userAddress, Password); } else { globalClient.Login(userAddress, Password, onMessage); } } else if (onMessage != null) { globalClient.FetchMessages(onMessage); } return(globalClient); }