Mail Flow
This code sample retrieves the following parameters of an Exchange mailbox:
-
Delivery Options
- Forward to
- Deliver message to both forwarding address and mailbox
- Recipients limits
-
Message Size Restrictions
- Maximum receiving message size
- Maximum sending message size
-
Message Delivery Restrictions
- Accept messages from
- Reject messages from
In the below code sample, the $mailboxParams variable represents properties of an Exchange mailbox. To retrieve the properties, use the IAdmExchangeMailParametersOps::GetMailParameters method.
How
[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=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Get Exchange properties
$mailboxParams = $user.GetMailParameters()
# The $mailboxParams variable represents properties of an Exchange mailbox
# Get 'Delivery Options'
$deliveryOptions = $mailboxParams.MailFlowSettings.DeliveryOptions
# Forward to
$forwardTo = $deliveryOptions.ForwardingAddress.DisplayName
Write-host "Mail forwarding: " -NoNewline
if ($forwardTo -ne $null)
{
Write-Host "Enabled"
Write-host "`tForward to: $forwardTo"
# Deliver message to both forwarding address and mailbox
Write-Host "`tDeliver message to both forwarding address and mailbox:" `
$deliveryOptions.DeliverToMailboxAndForward
}
else
{
Write-Host "Disabled"
}
# Recipients limits
$recipientsLimits = $deliveryOptions.RecipientLimits
Write-Host "Recipients limits: " -NoNewline
if ($recipientsLimits -eq -1)
{
Write-Host "Unlimited"
}
else
{
Write-Host $recipientsLimits
}
# Get 'Message Size Restrictions'
$messageSizeRestrictions = $mailboxParams.MailFlowSettings.MessageSizeRestrictions
# Maximum receiving message size
$maxReceiveSize = $messageSizeRestrictions.MaxReceiveSize
Write-Host "Maximum receiving message size: " -NoNewline
if ($maxReceiveSize -ne $null)
{
Write-Host $maxReceiveSize.GetKBytes()
}
else
{
Write-Host "Unlimited"
}
# Maximum sending message size
$maxSendSize = $messageSizeRestrictions.MaxSendSize
Write-Host "Maximum sending message size: " -NoNewline
if ($maxSendSize -ne $null)
{
Write-Host $maxSendSize.GetKBytes()
}
else
{
Write-Host "Unlimited"
}
# Get 'Message Delivery Restrictions'
$messageDeliveryRestrictions = $mailboxParams.MailFlowSettings.MessageDeliveryRestrictions
# Get list of accepted senders
$acceptMessagesFrom = $messageDeliveryRestrictions.AcceptMessagesOnlyFrom
# Accept messages only from senders inside my organization
$requireSenderAuthentication = $messageDeliveryRestrictions.RequireSenderAuthentication
if (($acceptMessagesFrom.Count -eq 0) -and (-not($requireSenderAuthentication)))
{
Write-Host "Accept messages from: All senders"
}
elseif ($requireSenderAuthentication)
{
Write-Host "Accept messages from: Only senders inside my organization"
}
else
{
Write-Host "Accept messages from the following senders only:"
for ($i = 0; $i -lt $acceptMessagesFrom.Count; $i++)
{
$object = $acceptMessagesFrom.GetItem($i, [ref]"ADS_PROPERTY_NONE")
Write-host "`t" $object.DisplayName
}
}
# Get list of rejected senders
$rejectMessagesFrom = $messageDeliveryRestrictions.RejectMessagesFrom
if ($rejectMessagesFrom.Count -eq 0)
{
Write-Host "Reject messages from: No senders"
}
else
{
Write-Host Reject messages from:"
for ($i = 0; $i -lt $rejectMessagesFrom.Count; $i++)
{
$object = $rejectMessagesFrom.GetItem($i, [ref]"ADS_PROPERTY_NONE")
Write-host "`t" $object.DisplayName
}
}
See also
- Performing Exchange tasks
- Writing ADSI scripts
- Server-side scripting
- IAdmExchangeMailParametersOps
- IAdmExchangeMailParameters
- IAdmExchangeMailboxParameters
- IAdmExchangeMailFlowSettings
- Online script repository