TargetAddress, ExternalEmailAddress and Set As External

In co-existence scenarios, the targetAddress attribute is leveraged to accomplish routing to different Exchange organizations by specifying the “final destination” e-mail address. The e-mail domain part of this address can be a non-accepted domain (i.e. other organization). This will enable organizations, when used in conjunction with mail-enabled users or contacts, to provision the (global) address list of their Exchange organization with mail-enabled objects of other organizations, also in a migration co-existence phase. Simply said:

  1. It can allow users in the local organization to select the object from the (global) address list and that object exists in other organizations;
  2. Exchange can route the message to its final destination using the specified targetAddress.

Reason for this blog is that I still see people putting e-mail address in the targetAddress property or the object by scripting against Active Directory (e.g. ADSI), even while they’re scripting using the Exchange Management Shell.

In the Exchange Management Shell, you can set the targetAddress by using the Set-MailContact or Set-MailUser in conjunction with the ExternalEmailAddress parameter, e.g.:

Set-MailContact  michel -ExternalEmailAddress michel@contoso.com

Setting this address is also possible using the Exchange Management Console, which may be more appropriate for testing purposes or a small number of changes (though I’d prefer the less-prone-to-error script any day):

image

When utilized in scripts, you can use PowerShell Piping Power (is that abbreviation already taken?) to process (CSV) files or use filtering to select the objects of which you want to configure the targetAddress, e.g.:

Get-MailContact -OrganizationalUnit “contoso.local/Division” -Filter {EmailAddresses -like *@contoso.local} -ResultSize unlimited | ForEach { Set-MailContact –ExternalEmailAddress “$($_.Alias)@newcompany.local” }

Get-Content “users.txt” | Get-MailContact | ForEach{ Set-MailContact $_.Identity -ExternalEmailAddress “$($_.Alias)@newcompany.local”  }

This will configure all mail-enabled contacts in the Division OU with an @contoso.local e-mail address with a target address which consists of the current alias followed by @newcompany.local. The other example uses a text file with names to process contacts and set the targetAddress to the current value of “alias” followed by the external e-mail domain.

Needless to say, the connectors between contoso and newcompany  as well as the accepted domains should be properly configured to route those contoso.local and newcompany.local domains between those organizations. Of course, this also depends on whether you’re using internal or external domain names and if you want those messages to go through the public network or not.

Note that this is also how you can set configure the targetAddress of a local (DirSync’ed) mail-enabled contact with an Office 365 mailbox in a Hybrid setup, for example after moving the mailbox to Office 365. In such case you set the targetAddress to the service domain in a Hybrid Office 365 setup, e.g. mydomain.mail.onmicrosoft.com.

2 thoughts on “TargetAddress, ExternalEmailAddress and Set As External

  1. Pingback: Exchnage – Forwarding And Redirection | FICILITY.NET

  2. You, sir, are absolutely right on the money with this post. I had the exact same problem dealing with a child domain that was sync’ed to O365, but the parent domain was not. Hybrid setup with Office 2010. Mail from parent.net (on-premises) to child.parent.net would not flow if the primary address for the users in O365 were set as SMTP:child.parent.net. Setting the “targetaddress” attribute allows the mail to flow. I spent almost 2 weeks with MS support, and they could not tell me this. You, however, win the prize.
    By running the following script, I was able to fix the issue for ALL user accounts (this also sets the primary SMTP address for the users as well.

    $s = Get-ADUser -SearchBase “ou=OUofUserAccts,dc=site,dc=domain,dc=local” -resultsetsize $null -filter *
    $s | foreach {
    set-aduser $_.samaccountname -add @{“targetaddress” = $_.samaccountname + “@O365domain.net”}
    }
    $s | foreach {
    set-aduser $_.samaccountname -add @{“proxyaddresses” = “SMTP:” + $_.samaccountname + “@o365domain.net”}
    }

    So…this fixed what MS couldn’t figure out after working with them for over a week! Over 25K accounts, fixed in about an hour and a DirSync setting. Brilliant!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s