Mail Flow

Modify delivery options

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"

$deliveryOptions = $mailboxParams.MailFlowSettings.DeliveryOptions
$deliveryOptions.IsModificationEnabled = $true

# Update the 'Forward to' parameter
# DN of the group that will receive messages from the mailbox
$groupDN = "CN=Managers,CN=Users,DC=example,DC=com"

$objReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$objReference.ObjectDN = $groupDN

$deliveryOptions.ForwardingAddress = $objReference

# Enable the 'Deliver message to both forwarding address and mailbox' option
$deliveryOptions.DeliverToMailboxAndForward = $true

# Update Recipients Limits 
$deliveryOptions.RecipientLimits = 10

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Modify message size restrictions

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"

$messageSizeRestrictions = $mailboxParams.MailFlowSettings.MessageSizeRestrictions
$messageSizeRestrictions.IsModificationEnabled = $true

# Set maximum receiving message size to 25 MB
$maxReceiveSize = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmByteQuantifiedSize"
$maxReceiveSize.SetMBytes(25)

$messageSizeRestrictions.MaxReceiveSize = $maxReceiveSize

# Set maximum sending message size to 25 MB
$MaxSendSize = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmByteQuantifiedSize"
$MaxSendSize.SetMBytes(25)
$messageSizeRestrictions.MaxSendSize = $MaxSendSize

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Modify message delivery restrictions

The following code sample configures a mailbox to only accept messages inside its organization.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"

$messageDeliveryRestrictions = $mailboxParams.MailFlowSettings.MessageDeliveryRestrictions
$messageDeliveryRestrictions.IsModificationEnabled = $true

$messageDeliveryRestrictions.RequireSenderAuthentication = $true
$messageDeliveryRestrictions.AcceptMessagesOnlyFrom.OverrideOldValues = $true
$messageDeliveryRestrictions.AcceptMessagesOnlyFromModificationEnabled = $true

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

The following code sample configures a mailbox to accept messages from all senders.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"

$messageDeliveryRestrictions = $mailboxParams.MailFlowSettings.MessageDeliveryRestrictions
$messageDeliveryRestrictions.IsModificationEnabled = $true

$groupDN = "CN=Sales Staff,CN=Users,DC=example,DC=com"

$objReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$objReference.ObjectDN = $groupDN

$acceptMessagesOnlyFrom = $messageDeliveryRestrictions.AcceptMessagesOnlyFrom
$acceptMessagesOnlyFrom.OverrideOldValues = $false
$acceptMessagesOnlyFrom.Add("ADS_PROPERTY_APPEND", $objReference)
$messageDeliveryRestrictions.AcceptMessagesOnlyFrom = $acceptMessagesOnlyFrom

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

The following code sample configures a mailbox to only accept messages from a specific group.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"

$messageDeliveryRestrictions = $mailboxParams.MailFlowSettings.MessageDeliveryRestrictions
$messageDeliveryRestrictions.IsModificationEnabled = $true

$groupDN = "CN=Sales Staff,CN=Users,DC=example,DC=com"

$objReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$objReference.ObjectDN = $groupDN

$acceptMessagesOnlyFrom = $messageDeliveryRestrictions.AcceptMessagesOnlyFrom
$acceptMessagesOnlyFrom.OverrideOldValues = $false
$acceptMessagesOnlyFrom.Add("ADS_PROPERTY_APPEND", $objReference)
$messageDeliveryRestrictions.AcceptMessagesOnlyFrom = $acceptMessagesOnlyFrom

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

The following code sample configures a mailbox to reject messages from a specific group.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"

$messageDeliveryRestrictions = $mailboxParams.MailFlowSettings.MessageDeliveryRestrictions
$messageDeliveryRestrictions.IsModificationEnabled = $true

$groupDN = "CN=Sales Staff,CN=Users,DC=example,DC=com"

$objReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$objReference.ObjectDN = $groupDN

$rejectMessagesFrom = $messageDeliveryRestrictions.RejectMessagesFrom
$rejectMessagesFrom.OverrideOldValues = $false
$rejectMessagesFrom.Add("ADS_PROPERTY_APPEND", $objReference)
$messageDeliveryRestrictions.RejectMessagesFrom = $rejectMessagesFrom

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

See also