public static void Connect( this MailBoxDto mailBox, IImapClient client, CancellationTokenSource cancelToken) { client.Connect(mailBox.Server, mailBox.Port, MailKit.Security.SecureSocketOptions.Auto, cancelToken.Token); }
public EmailService(IImapClient client) { if (client == null) { throw new ArgumentNullException("client"); } _imapClient = client; }
/// <summary> /// Returns imap folders collection. /// </summary> /// <param name="mailboxId">Mailbox sync settings Id.</param> /// <param name="mailServerId">Mail server Id.</param> /// <param name="mailboxName">Mailbox name.</param> /// <param name="mailboxPassword">Mailbox password.</param> /// <returns>Imap folders collection.</returns> protected virtual List <IImapFolder> GetImapFolders(string mailboxId, string mailServerId, string mailboxName, string mailboxPassword) { try { IImapClient imapClient = !string.IsNullOrEmpty(mailboxId) ? GetImapClientByMailboxId(mailboxId, out mailboxName) : GetImapClient(mailServerId, mailboxName, mailboxPassword); return(imapClient.GetFolders()); } catch (Exception e) { _log.ErrorFormat("GetImapFolders method error for {0} mailbox.", e, mailboxName); } return(null); }
public void Connect(MapConfig config) { try { _log.Info("Connecting to SMTP server"); _client = new ImapClient(config.Host, config.Port, config.Ssl); _log.Info("logging to SMTP server"); this.Authentificate(config); } catch (Exception ex) { _log.Error(ex); } }
private static IObservable<IMessage> SearchImap(IImapClient imapClient, IEnumerable<string> contactKeys, IAccount account) { var query = from isConnected in imapClient.Connect("imap.gmail.com", 993) .Select(isConnected => { if (isConnected) return true; throw new IOException("Failed to connect to Gmail IMAP server."); }) from isAuthenticated in imapClient.Authenticate(account.AccountId, account.CurrentSession.AccessToken) .Select(isAuthenticated => { if (isAuthenticated) return true; throw new AuthenticationException("Failed to authenticate for Gmail search."); }) from isSelected in imapClient.SelectFolder("[Gmail]/All Mail") let queryText = ToSearchQuery(contactKeys) from emailIds in imapClient.FindEmailIds(queryText) from email in imapClient.FetchEmailSummaries(emailIds.Reverse(), account.Handles.Single(ch => ch.HandleType == ContactHandleTypes.Email).Handle) select email; return query.Distinct(msg => msg.DeepLink) .Take(10); }
public IdleErrorEventArgsWrapper(IImapClient client, Exception exception) { Client = client; Exception = exception; }
public IdleMessageEventArgsWrapper(IImapClient client) { Client = client; }
public void Should_Throw_With_Null_Client() { IImapClient client = null; var target = new EmailService(client); }
public virtual async Task Setup(bool isRecoverySetup = false) { //we should throw an exception if the initial setup is unable to successfully get a client //but after that we know that credentials are good and should handle exceptions for any new clients that we need to create if (isRecoverySetup) { try { if (ImapClient != null && ImapClient.IsConnected) { await ImapClient.DisconnectAsync(true, Util.GetCancellationToken(15000)); } ImapClient = await Factory.GetClient(); } catch (Exception ex) { Trace.WriteLine(ex.Message); //wait 10 seconds before trying again await Task.Delay(10000); await Setup(true); return; } } else { ImapClient = await Factory.GetClient(); } ImapClient.Disconnected += (sender, args) => { Trace.WriteLine("ImapClient disconnected"); }; ImapClient.Inbox.Opened += (sender, args) => { Trace.WriteLine($"{Factory.MailBoxName} {GetType().Name} Inbox opened"); }; ImapClient.Inbox.Closed += (sender, args) => { Trace.WriteLine($"{Factory.MailBoxName} {GetType().Name} Inbox closed"); }; IdleTask = null; Trace.WriteLine($"{Factory.MailBoxName}: {GetType().Name} setup complete"); IntegrityCheckTimer.Start(); await StartIdling(); }