![](/img/trans.png)
[英]Querying the Global Address List (GAL) via Exchange Web Services (EWS) erreor SSL
[英]Exchange Web Service Create a contact and add to global address list
我正在尝试使用EWS将外部联系人添加到全局地址列表中。 到目前为止,我还没有这样做。 事件新添加的联系人在用户主要联系人列表中不可见。 我在这里想念什么吗? 我试过两个版本。 一种使用EWS的方法,如下所示:
var service = InitConnection(exchangeUrl, exchangeUsername);
if (service == null)
{
return "Failed to connect to exchange server";
}
try
{
var data = (Hashtable)contactKeyValues;
if (data == null && data.Count <= 0)
{
return "The data can't be extracted. Please check your dictionary parameter of properties.";
}
var localExchangeContactObj = ValidateAndBuildContact(data);
var remoteExchangeContactObj = new Contact(service);
remoteExchangeContactObj.GivenName = localExchangeContactObj.FirstName;
remoteExchangeContactObj.Surname = localExchangeContactObj.LastName;
remoteExchangeContactObj.Initials = localExchangeContactObj.Initials;
remoteExchangeContactObj.FileAsMapping = FileAsMapping.GivenNameSpaceSurname;
remoteExchangeContactObj.PhoneNumbers[PhoneNumberKey.BusinessPhone] = localExchangeContactObj.PhoneBusiness;
remoteExchangeContactObj.PhoneNumbers[PhoneNumberKey.HomePhone] = localExchangeContactObj.PhoneHome;
remoteExchangeContactObj.EmailAddresses[EmailAddressKey.EmailAddress1] = localExchangeContactObj.Email;
var address = new PhysicalAddressEntry();
address.Street = localExchangeContactObj.Address;
address.City = localExchangeContactObj.City;
address.State = localExchangeContactObj.State;
address.PostalCode = localExchangeContactObj.Zip;
address.CountryOrRegion = localExchangeContactObj.Country;
remoteExchangeContactObj.PhysicalAddresses[PhysicalAddressKey.Business] = address;
remoteExchangeContactObj.Body = new MessageBody(BodyType.HTML, localExchangeContactObj.Notes);
remoteExchangeContactObj.Save(WellKnownFolderName.Contacts);
return remoteExchangeContactObj.Id.UniqueId.ToString();
}
catch (Exception exception)
{
return string.Format("Something went wrong while creating contact in exchnage. Here is the details {0}", exception.ToString());
}
另一种方法是通过LDAP,在这种情况下,它将在当前OU中创建联系人,但不会在搜索时显示。 代码如下:
try
{
DirectoryEntry de;
if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password))
{
de = new DirectoryEntry(ldapPath);
}
else
{
de = new DirectoryEntry(ldapPath, username, password);
}
var newContact = de.Children.Add("CN=" + name, "contact");
newContact.Properties["mail"].Value = email;
de.CommitChanges();
}
catch (COMException comEx)
{
var eventLog = new EventLog { Source = "Exchange Integration Create Contact" };
eventLog.WriteEntry(string.Format("Exception while creating contact {0} ", comEx), EventLogEntryType.Error);
return comEx.ErrorCode.ToString();
}
catch (Exception exception)
{
var eventLog = new EventLog { Source = "Exchange Integration Create Contact" };
eventLog.WriteEntry(string.Format("Exception while creating contact {0} ", exception), EventLogEntryType.Error);
return exception.ToString();
}
return "Contact created";
您无法使用EWS在GAL中创建联系人,EWS是一个邮箱访问API,因此您可以在代码的尝试中在邮箱的联系人文件夹中创建联系人。 但是,这些将不会出现在“全局地址列表”中。 创建将出现在GAL中的联系人的唯一受支持方法是使用Exchange命令行管理程序New-MailConact https://technet.microsoft.com/zh-cn/library/bb124519(v=exchg.150).aspx cmdlet并通过https://msdn.microsoft.com/zh-cn/library/office/ff326159(v=exchg.150).aspx在托管代码中使用远程Powershell。 这将创建一个启用邮件的AD联系人。 (您的LDAP代码正在创建联系人,但是如果您确实想沿途使用,则将无法启用邮件,您需要设置更多属性(例如TargetAddress等)来查看已启用邮件的联系人)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.