Mail Flow

This code sample retrieves the following parameters of a mail-enabled contact:

  • 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 $contactParams variable represents Exchange properties of a mail-enabled contact. 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 contact
$contactDN = "CN=My Contact,CN=Contacts,DC=domain,DC=com"
$contact = $service.OpenObject("Adaxes://$contactDN", $null, $null, 0)

# Get Exchange properties
$contactParams = $contact.GetMailParameters()
# The $contactParams variable represents Exchange properties of a mail-enabled contact

# Get message size restrictions
$messageSizeRestrictions = $contactParams.MailFlowSettings.MessageSizeRestrictions

# Maximum receiving message size
$maxReceiveSize = $messageSizeRestrictions.MaxReceiveSize
if ($maxReceiveSize -ne $null)
{
    Write-Host "Maximum receiving message size:" $maxReceiveSize.GetKBytes()
}

# Maximum sending message size
$maxSendSize = $messageSizeRestrictions.MaxSendSize
if ($maxSendSize -ne $null)
{
    Write-Host "Maximum sending message size:" $maxSendSize.GetKBytes()
}

# Get message delivery restrictions
$messageDeliveryRestrictions = $contactParams.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:"
    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