Exemple #1
0
        private List <CommandParameter> GetOutboundConnectorParameters(bool isNew)
        {
            List <CommandParameter> list = new List <CommandParameter>();

            if (this.CentralizedTransportEnabled != null || this.OutboundDomains != null)
            {
                bool addWildcard = false;
                if (this.CentralizedTransportEnabled != null)
                {
                    addWildcard = this.CentralizedTransportEnabled.Value;
                }
                else if (base.OriginalInboundConnector != null && base.OriginalOutboundConnector != null)
                {
                    HybridMailflowConfiguration hybridMailflowConfiguration = HybridMailflowTaskBase.ConvertToHybridMailflowConfiguration(base.OriginalInboundConnector, base.OriginalOutboundConnector);
                    addWildcard = (hybridMailflowConfiguration.CentralizedTransportEnabled != null && hybridMailflowConfiguration.CentralizedTransportEnabled.Value);
                }
                if (this.OutboundDomains != null && HybridMailflowTaskBase.IsRecipientDomainsWildcard(this.OutboundDomains))
                {
                    addWildcard = true;
                }
                List <SmtpDomainWithSubdomains> value = (this.OutboundDomains != null) ? HybridMailflowTaskBase.GetRecipientDomains(this.OutboundDomains, addWildcard) : HybridMailflowTaskBase.GetRecipientDomains(base.OriginalOutboundConnector, addWildcard);
                list.Add(new CommandParameter("RecipientDomains", value));
            }
            if (this.CentralizedTransportEnabled != null && this.CentralizedTransportEnabled.Value)
            {
                list.Add(new CommandParameter("RouteAllMessagesViaOnPremises", this.CentralizedTransportEnabled.Value));
            }
            if (this.OnPremisesFQDN != null)
            {
                list.Add(new CommandParameter("SmartHosts", this.OnPremisesFQDN.ToString()));
                list.Add(new CommandParameter("UseMxRecord", false));
            }
            if (this.CertificateSubject != null)
            {
                list.Add(new CommandParameter("TlsDomain", this.CertificateSubject));
            }
            if (this.SecureMailEnabled != null)
            {
                list.Add(new CommandParameter("TlsSettings", this.SecureMailEnabled.Value ? new TlsAuthLevel?(TlsAuthLevel.DomainValidation) : null));
            }
            if (isNew)
            {
                if (base.OrganizationName != null)
                {
                    list.Add(new CommandParameter("Organization", base.OrganizationName));
                }
                list.Add(new CommandParameter("Name", "Hybrid Mail Flow Outbound Connector"));
                list.Add(new CommandParameter("Comment", Strings.HybridMailflowOutboundConnectorComment));
                list.Add(new CommandParameter("Enabled", true));
                list.Add(new CommandParameter("ConnectorType", "OnPremises"));
                list.Add(new CommandParameter("ConnectorSource", "HybridWizard"));
                list.Add(new CommandParameter("CloudServicesMailEnabled", true));
            }
            else
            {
                list.Add(new CommandParameter("Identity", base.OriginalOutboundConnector.Identity));
            }
            return(list);
        }
        protected static List <SmtpDomainWithSubdomains> GetRecipientDomains(TenantOutboundConnector outboundConnector, bool addWildcard)
        {
            IEnumerable <SmtpDomainWithSubdomains> domains = null;

            if (outboundConnector != null && outboundConnector.RecipientDomains != null)
            {
                domains = outboundConnector.RecipientDomains;
            }
            return(HybridMailflowTaskBase.GetRecipientDomains(domains, addWildcard));
        }
 protected override void InternalProcessRecord()
 {
     if (base.OriginalInboundConnector == null)
     {
         base.WriteVerbose(base.NullInboundConnectorMessage);
         return;
     }
     if (base.OriginalOutboundConnector == null)
     {
         base.WriteVerbose(base.NullOutboundConnectorMessage);
         return;
     }
     base.WriteObject(HybridMailflowTaskBase.ConvertToHybridMailflowConfiguration(base.OriginalInboundConnector, base.OriginalOutboundConnector));
 }
 protected static bool IsRecipientDomainsWildcard(IEnumerable <SmtpDomainWithSubdomains> domains)
 {
     if (domains != null)
     {
         foreach (SmtpDomainWithSubdomains domain in domains)
         {
             if (HybridMailflowTaskBase.IsWildcardDomain(domain))
             {
                 return(true);
             }
         }
         return(false);
     }
     return(false);
 }
        protected static HybridMailflowConfiguration ConvertToHybridMailflowConfiguration(TenantInboundConnector inbound, TenantOutboundConnector outbound)
        {
            ArgumentValidator.ThrowIfNull("inbound", inbound);
            ArgumentValidator.ThrowIfNull("outbound", outbound);
            HybridMailflowConfiguration hybridMailflowConfiguration = new HybridMailflowConfiguration();

            hybridMailflowConfiguration.OutboundDomains = new List <SmtpDomainWithSubdomains>();
            foreach (SmtpDomainWithSubdomains smtpDomainWithSubdomains in outbound.RecipientDomains)
            {
                if (!HybridMailflowTaskBase.IsWildcardDomain(smtpDomainWithSubdomains))
                {
                    hybridMailflowConfiguration.OutboundDomains.Add(new SmtpDomainWithSubdomains(smtpDomainWithSubdomains.Address));
                }
            }
            if (inbound.SenderIPAddresses != null)
            {
                hybridMailflowConfiguration.InboundIPs = new List <IPRange>();
                foreach (IPRange item in inbound.SenderIPAddresses)
                {
                    hybridMailflowConfiguration.InboundIPs.Add(item);
                }
            }
            if (!MultiValuedPropertyBase.IsNullOrEmpty(outbound.SmartHosts))
            {
                SmartHost smartHost = outbound.SmartHosts[0];
                if (smartHost.IsIPAddress)
                {
                    hybridMailflowConfiguration.OnPremisesFQDN = new Fqdn(smartHost.Address.ToString());
                }
                else
                {
                    hybridMailflowConfiguration.OnPremisesFQDN = new Fqdn(smartHost.ToString());
                }
            }
            if (inbound.TlsSenderCertificateName != null)
            {
                hybridMailflowConfiguration.CertificateSubject = inbound.TlsSenderCertificateName.ToString();
            }
            hybridMailflowConfiguration.SecureMailEnabled           = new bool?(inbound.RequireTls && outbound.TlsSettings != null && outbound.TlsSettings == TlsAuthLevel.DomainValidation);
            hybridMailflowConfiguration.CentralizedTransportEnabled = new bool?((inbound.RestrictDomainsToIPAddresses && HybridMailflowTaskBase.IsRecipientDomainsWildcard(outbound.RecipientDomains)) || outbound.RouteAllMessagesViaOnPremises);
            return(hybridMailflowConfiguration);
        }
        protected static List <SmtpDomainWithSubdomains> GetRecipientDomains(IEnumerable <SmtpDomainWithSubdomains> domains, bool addWildcard)
        {
            List <SmtpDomainWithSubdomains> result = new List <SmtpDomainWithSubdomains>();

            if (addWildcard)
            {
                HybridMailflowTaskBase.AddRecipientDomain(ref result, SmtpDomainWithSubdomains.StarDomain);
            }
            if (domains != null)
            {
                foreach (SmtpDomainWithSubdomains domain in domains)
                {
                    if (!HybridMailflowTaskBase.IsWildcardDomain(domain))
                    {
                        HybridMailflowTaskBase.AddRecipientDomain(ref result, domain);
                    }
                }
            }
            return(result);
        }