Example #1
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 #2
0
        public bool CreateBPMOnlineFolder(Guid id, string userName, string userPassword)
        {
            var currentMailServer = new MailServer(UserConnection);

            if (!currentMailServer.FetchFromDB(id))
            {
                return(false);
            }
            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     = userName,
                UserPassword = userPassword
            };
            var imapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection);

            imapClient.EnsureFolderExists("BPMonline");
            var mailboxFolderTypeId = new Guid("99c2351c-f0f8-e111-9dba-00155d051801");
            var emailFolderTypeId   = new Guid("b97a5836-1cd0-e111-90c6-00155d054c03");
            var mailboxFolder       = new ActivityFolder(UserConnection);

            if (mailboxFolder.FetchFromDB(
                    new Dictionary <string, object> {
                { "FolderType", mailboxFolderTypeId },
                { "Name", imapServerCredentials.UserName }
            }))
            {
                var activityFolderSchema = UserConnection.EntitySchemaManager.GetInstanceByName("ActivityFolder");
                var bpmonlineFolder      = activityFolderSchema.CreateEntity(UserConnection);
                var parentColumn         = activityFolderSchema.Columns.GetByName("Parent");
                var folderTypeColumn     = activityFolderSchema.Columns.GetByName("FolderType");
                bpmonlineFolder.SetDefColumnValues();
                bpmonlineFolder.SetColumnValue("Name", "BPMonline");
                bpmonlineFolder.SetColumnValue(parentColumn.ColumnValueName, mailboxFolder.PrimaryColumnValue);
                bpmonlineFolder.SetColumnValue(folderTypeColumn.ColumnValueName, emailFolderTypeId);
                bpmonlineFolder.Save();
                return(true);
            }
            return(false);
        }
        /// <inheritdoc cref="IMailboxValidator.ValidateSynchronization"/>
        public CredentialsValidationInfo ValidateSynchronization(Mailbox mailbox)
        {
            var answer = new CredentialsValidationInfo {
                IsValid = true
            };

            try {
                var imapClient = new ImapClient(new MailCredentials {
                    UserName           = mailbox.Login,
                    UserPassword       = mailbox.Password,
                    SenderEmailAddress = mailbox.SenderEmailAddress,
                    Host   = mailbox.GetServerAddress(),
                    Port   = mailbox.GetServerPort(),
                    UseSsl = mailbox.UseSsl
                }, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true);
            }
            catch (ImapException exception) {
                answer.IsValid = false;
                answer.Message = ConnectToServerCaption + exception.Message;
            }
            return(answer);
        }
Example #4
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 #5
0
        public IsValidAnswer IsServerValid(Guid id, string userName, string userPassword, bool enableSync,
                                           bool sendEmail, string senderEmailAddress, bool isAnonymousAuthentication)
        {
            var currentMailServer = new MailServer(UserConnection);
            var isValidAnswer     = new IsValidAnswer()
            {
                IsValid = true,
                Message = string.Empty
            };

            if (!currentMailServer.FetchFromDB(id))
            {
                isValidAnswer.IsValid = false;
                return(isValidAnswer);
            }
            if (currentMailServer.AllowEmailDownloading && enableSync)
            {
                try {
                    var imapServerCredentials = new MailCredentials {
                        Host         = currentMailServer.Address,
                        Port         = currentMailServer.Port,
                        UseSsl       = currentMailServer.UseSSL,
                        StartTls     = currentMailServer.IsStartTls,
                        UserName     = userName,
                        UserPassword = userPassword
                    };
                    var mapClient = new ImapClient(imapServerCredentials, MailSynchronizer.GetImapErrorMessages(UserConnection), UserConnection, true);
                } catch (ImapException exception) {
                    isValidAnswer.IsValid = false;
                    isValidAnswer.Message = ConnectToImapServerCaption.ToString() + exception.Message;
                }
            }
            if (currentMailServer.AllowEmailSending && sendEmail)
            {
                var smtpServerCredentials = new MailCredentials();
                if (isAnonymousAuthentication)
                {
                    smtpServerCredentials.IsAnonymousAuthentication = true;
                }
                else
                {
                    smtpServerCredentials.UserName     = userName;
                    smtpServerCredentials.UserPassword = userPassword;
                }
                smtpServerCredentials.Host               = currentMailServer.SMTPServerAddress;
                smtpServerCredentials.Port               = currentMailServer.SMTPPort;
                smtpServerCredentials.UseSsl             = currentMailServer.UseSSLforSending;
                smtpServerCredentials.StartTls           = currentMailServer.IsStartTls;
                smtpServerCredentials.Timeout            = currentMailServer.SMTPServerTimeout * 1000;
                smtpServerCredentials.SenderEmailAddress = senderEmailAddress;

                var smtpClient = new SmtpClient(UserConnection, smtpServerCredentials);
                try {
                    smtpClient.SendTestMessage();
                } catch (SmtpException ex) {
                    if (!string.IsNullOrEmpty(isValidAnswer.Message))
                    {
                        isValidAnswer.Message += Environment.NewLine;
                    }
                    isValidAnswer.IsValid  = false;
                    isValidAnswer.Message += CanNotSendTestMessageCaption.ToString() + ex.Message;
                }
            }
            return(isValidAnswer);
        }