/// <summary>
        /// Gets exchange server email events subscription credentials.
        /// </summary>
        /// <param name="mailbox"><see cref="Mailbox"/> instance.</param>
        /// <returns><see cref="SynchronizationCredentials"/> instance.</returns>
        private SynchronizationCredentials GetSynchronizationCredentials(Mailbox mailbox)
        {
            var credentials = mailbox.ConvertToSynchronizationCredentials(UserConnection);

            credentials.BpmEndpoint = GetBpmEndpointUrl();
            return(credentials);
        }
        /// <inheritdoc cref="IMailboxValidator.ValidateSynchronization"/>
        public CredentialsValidationInfo ValidateSynchronization(Mailbox mailbox)
        {
            var answer = new CredentialsValidationInfo()
            {
                IsValid = true
            };
            var credentials = mailbox.ConvertToSynchronizationCredentials(UserConnection);

            ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            _ignoreSslWarnings = (bool)Terrasoft.Core.Configuration.SysSettings.GetValue(UserConnection, "IgnoreExchangeSSLWarnings");
            try {
                var service = _exchangeUtility.CreateExchangeService(UserConnection, credentials,
                                                                     credentials.SenderEmailAddress);
                Exchange.NameResolutionCollection resolutions = service.ResolveName(credentials.SenderEmailAddress);
                var mailboxName = string.Empty;
                if (resolutions.Any())
                {
                    Exchange.EmailAddress mailboxAddress = resolutions.First().Mailbox;
                    mailboxName = mailboxAddress.Name;
                }
                answer.Data = JsonConvert.SerializeObject(new {
                    MailboxName = mailboxName
                });
            } catch (Exception exception) {
                answer.IsValid = false;
                answer.Message = ConnectToServerCaption + exception.Message;
            } finally {
                ServicePointManager.ServerCertificateValidationCallback -= ValidateRemoteCertificate;
            }
            return(answer);
        }
Пример #3
0
        /// <summary>
        /// Gets mail server <see cref="SynchronizationCredentials"/>.
        /// </summary>
        /// <param name="mailbox"><see cref="Mailbox"/> instance.</param>
        /// <returns><see cref="SynchronizationCredentials"/> instance.</returns>
        private SynchronizationCredentials GetSynchronizationCredentials(Mailbox mailbox)
        {
            var credentials = mailbox.ConvertToSynchronizationCredentials(UserConnection);
            var utils       = ClassFactory.Get <ListenerUtils>(new ConstructorArgument("uc", UserConnection),
                                                               new ConstructorArgument("context", Context));

            credentials.BpmEndpoint = utils.GetBpmEndpointUrl();
            return(credentials);
        }