简体   繁体   中英

Adding Exchange E-mail Alias in VB.NET or C#

Using .NET (VB or C#), how can I add an e-mail alias to a user in Active Directory?

I have written code to change the format of our usernames from "first_last" to "first.last.country" and I need to update the e-mail addresses as well. Our solution is to add an alias e-mail to the users in exchange, but I don't know how I can do this using .NET.

This question is quite old but, you never know who may need this info.

The modern way to handle Exchange Server and Active Directory issues at this level is not using vb or c# , sure you can, but the practical and fast) way to do it is using 'powershell' .

On your exchange server use Powershell ISE ; it isvery close to a programming language. There are multiple samples elsewhere of aliases handling.

Here you have the basics: You start loading your environment, your location and version may vary:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1' 
Import-Module ActiveDirectory

Apply your own logic to get the user you want to modify and the alias:

$mb = get-Mailbox .....
$mb | Set-Mailbox -EmailAddressPolicyEnabled $false
$alias = "newalias@domain"
if(-not($mb.EmailAddresses -ccontains $alias)){
  $mb | Set-Mailbox -EmailAddresses @{Add="$alias" }
}

Here is a link to another question that may help.

C# - Find all email addresses for an Active Directory user

Niall

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM