private ImapClient GetImapClient(string mailServerUId, string mailboxName, string mailboxPassword) { var currentMailServer = new Terrasoft.Configuration.MailServer(UserConnection); if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading")) { return(null); } var imapServerCredentials = new MailCredentials { Host = currentMailServer.GetTypedColumnValue <string>("Address"), Port = currentMailServer.GetTypedColumnValue <int>("Port"), UseSsl = currentMailServer.GetTypedColumnValue <bool>("UseSSL"), StartTls = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"), UserName = mailboxName, UserPassword = mailboxPassword }; ImapClient imapClient; SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection); try { imapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true); } catch (Exception ex) { helper.ProcessSynchronizationError(mailboxName, ex, true); throw; } return(imapClient); }
private IImapClient GetImapClient(string mailServerUId, string mailboxName, string mailboxPassword) { var currentMailServer = new Terrasoft.Configuration.MailServer(UserConnection); if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading")) { return(null); } var imapServerCredentials = new MailCredentials { Host = currentMailServer.GetTypedColumnValue <string>("Address"), Port = currentMailServer.GetTypedColumnValue <int>("Port"), UseSsl = currentMailServer.GetTypedColumnValue <bool>("UseSSL"), StartTls = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"), UserName = mailboxName, UserPassword = mailboxPassword }; SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection); try { return(ClassFactory.Get <IImapClient>("OldEmailIntegration", new ConstructorArgument("credentials", imapServerCredentials), new ConstructorArgument("errorMessages", new Terrasoft.Mail.ImapErrorMessages()), new ConstructorArgument("userConnection", UserConnection), new ConstructorArgument("login", true))); } catch (Exception ex) { helper.ProcessSynchronizationError(mailboxName, ex, true); throw; } }
private ImapClient GetImapClientByMailboxId(string mailboxId, out string mailboxName) { mailboxName = string.Empty; var mailbox = new Terrasoft.Configuration.MailboxSyncSettings(UserConnection); if (!mailbox.FetchFromDB(new Guid(mailboxId))) { return(null); } mailboxName = mailbox.GetTypedColumnValue <string>("UserName"); var mailServerUId = mailbox.GetTypedColumnValue <Guid>("MailServerId"); var currentMailServer = new Terrasoft.Configuration.MailServer(UserConnection); if (!currentMailServer.FetchFromDB(mailServerUId) || !currentMailServer.GetTypedColumnValue <bool>("AllowEmailDownloading")) { return(null); } var imapServerCredentials = new MailCredentials { Host = currentMailServer.GetTypedColumnValue <string>("Address"), Port = currentMailServer.GetTypedColumnValue <int>("Port"), UseSsl = currentMailServer.GetTypedColumnValue <bool>("UseSSL"), UserName = mailbox.GetTypedColumnValue <string>("UserName"), UserPassword = mailbox.GetTypedColumnValue <string>("UserPassword"), StartTls = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"), SenderEmailAddress = mailbox.GetTypedColumnValue <string>("SenderEmailAddress"), }; SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection); ImapClient imapClient; try { imapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true); } catch (Exception ex) { helper.ProcessSynchronizationError(imapServerCredentials.SenderEmailAddress, ex, true); throw; } return(imapClient); }