简体   繁体   English

在VB.NET或C#中添加Exchange电子邮件别名

[英]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? 使用.NET(VB或C#),如何在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. 我已经编写了将用户名格式从“ first_last”更改为“ first.last.country”的代码,并且我还需要更新电子邮件地址。 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. 我们的解决方案是向用户添加一个别名电子邮件作为交换,但是我不知道如何使用.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' . 在这个级别上处理Exchange ServerActive Directory问题的现代方法不是使用vbc# ,当然可以,但是实用且快速的方法是使用'powershell'

On your exchange server use Powershell ISE ; 在您的交换服务器上,使用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 C#-查找Active Directory用户的所有电子邮件地址

Niall 尼尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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