Example #1
0
        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;
            }
        }
        /// <summary>
        /// Synchronizes email messages.
        /// </summary>
        /// <param name="syncAction">Sync action for <see cref="Envelope"/> instance.</param>
        /// <param name="crmFolders">Specific directories to synchronize.</param>
        /// <param name="loadAll">Defines the need to download all messages.</param>
        public void SyncMailMessages(Func <MailMessage, Envelope, bool, string, bool> syncAction, Dictionary <string, List <Guid> > crmFolders, bool loadAll = true)
        {
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(_userConnection);

            try {
                if (loadAll)
                {
                    _log.Info(string.Format("[{0}] | Loading emails from all folders", _currentMailboxName));
                    SyncAllFolders(syncAction, crmFolders);
                }
                else
                {
                    _log.Info(string.Format("[{0}] | Loading emails from selected folders", _currentMailboxName));
                    SyncSelectedFolders(syncAction, crmFolders);
                }
                helper.CleanUpSynchronizationError(_currentMailboxName);
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(_currentMailboxName, ex);
                if (ex is MailBeeException)
                {
                    throw new ImapException(LocSyncError.ToString(), ex);
                }
                throw ex;
            }
        }
Example #3
0
        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);
        }
Example #4
0
        /// <summary>
        /// Sends e-mail message <paramref name="emailMessage"/>.
        /// </summary>
        /// <param name="emailMessage">E-mail message.</param>
        /// <param name="ignoreRights">Flag that indicates whether to ignore rights.</param>
        public virtual void Send(EmailMessage emailMessage, bool ignoreRights = false)
        {
            SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(_userConnection);

            try {
                IEmailClient emailClient = _emailClientFactory
                                           .CreateEmailClient(emailMessage.From.ExtractEmailAddress(), ignoreRights);
                emailClient.Send(emailMessage, ignoreRights);
                ClearSyncError(helper, emailClient, emailMessage.From);
            } catch (Exception ex) {
                helper.ProcessSynchronizationError(emailMessage.From, ex);
                throw;
            }
        }
Example #5
0
        private IImapClient GetImapClientByMailboxId(string mailboxId, out string mailboxName)
        {
            mailboxName = string.Empty;
            var mailboxEntitySchema = UserConnection.EntitySchemaManager.GetInstanceByName("MailboxSyncSettings");
            var mailbox             = mailboxEntitySchema.CreateEntity(UserConnection);

            if (!mailbox.FetchFromDB(new Guid(mailboxId)))
            {
                return(null);
            }
            mailboxName = mailbox.GetTypedColumnValue <string>("UserName");
            var mailServerUId          = mailbox.GetTypedColumnValue <Guid>("MailServerId");
            var mailServerEntitySchema = UserConnection.EntitySchemaManager.GetInstanceByName("MailServer");
            var currentMailServer      = mailServerEntitySchema.CreateEntity(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"),
            };

            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) {
                SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(UserConnection);
                helper.ProcessSynchronizationError(imapServerCredentials.SenderEmailAddress, ex, true);
                throw;
            }
        }
Example #6
0
        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);
        }
Example #7
0
 /// <summary>
 /// Writes error message to the log, including information about the exception that caused this error.
 /// </summary>
 /// <param name="format">Format string with an informational message.</param>
 /// <param name="exception">Exeption.</param>
 /// <param name="args">Message format.</param>
 public override void LogError(string format, Exception exception, params object[] args)
 {
     base.LogError(format, exception, args);
     _syncErrorHelper.ProcessSynchronizationError(SenderEmailAddress, exception);
 }