//connect to server public void ConnectToServer(EmailBoxAkkaut account) { //#1 try connect to server on right port and domen try { _imapClient = new ImapClient(); _imapClient.Timeout = 20000; _logger.Info($"{_libName} try connnect to server"); _imapClient.Connect(account.Server, account.Port, SecureSocketOptions.None); _logger.Info($"{_libName} Connected to server"); account.ServerStatus = GoodState; } catch (Exception ex) { _logger.Error(ex.Message); account.ServerStatus = ex.Message; return; } //#2 try authenticate on server try{ _imapClient.Authenticate(account.Login, account.Pass); _logger.Info($"{_libName} Try auth to server"); _imapClient.Inbox.Open(FolderAccess.ReadWrite); _logger.Info($"{_libName} Authenticated"); account.AccountStatus = GoodState; } catch (Exception ex) { _logger.Error(ex.Message); account.AccountStatus = ex.Message; _imapClient.Dispose(); } }
public ObservableCollection <MimeMessage> ReaderMails(EmailBoxAkkaut akkaunt, string destFolderName, string trashFolderName, string stopWords) { //try connect to server ConnectToServer(akkaunt); if (_imapClient.IsConnected) { _destFolder = CheckFolderByName(destFolderName); _trashFolder = CheckFolderByName(trashFolderName); if (_destFolder == null) { _destFolder = CreateFolder(destFolderName); } if (_trashFolder == null) { _trashFolder = CreateFolder(trashFolderName); } //check foldes values if ((_destFolder == null) || (_trashFolder == null)) { _logger.Error($"ConnectToserver some problem with folders {trashFolderName} {destFolderName}"); return(null); } //check stop wors value if (stopWords.Length < 5) { _logger.Error($"ConnectToserver you didn't have stop words {stopWords}"); return(null); } _logger.Info($"{_libName} Destination folder - {_destFolder.FullName}; Trash folder - {_trashFolder.FullName}"); var resMessages = FilterMailsBySubject(stopWords); return(resMessages); } _logger.Error($"{_libName} Akkaunt status is {akkaunt.AccountStatus}"); return(null); }