C#EWS将联系人复制到邮箱

时间:2014-11-20 14:30:49

标签: c# exchange-server exchangewebservices

我想选择用户“test”,以便我可以在他的邮箱中创建联系人。

我的实际问题是它会在我的用户“c-sharp”中创建联系人。

“c-sharp”对“测试”邮箱具有完全访问权限

我更改了IP,联系人信息用户也只是用于测试。

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.EnableScpLookup = false;
service.Credentials = new WebCredentials("c-sharp", "c-sharp", "domain");
service.UseDefaultCredentials = false;
IgnoreBadCertificates();
service.Url = new Uri("https://192.000.000.000/EWS/Exchange.asmx");

Contact contact = new Contact(service);

// Specify the name and how the contact should be filed.
contact.GivenName = "n.a.";
contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
contact.DisplayName = "bau gmbh";

// Specify the company name.
contact.CompanyName = "bau";

// Specify the business, home, and car phone numbers.
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "00000 00000";
contact.PhoneNumbers[PhoneNumberKey.MobilePhone] = "n.a.";
contact.PhoneNumbers[PhoneNumberKey.BusinessFax] = "00000 00000";

// Specify two email addresses.
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress("e@mail.de");

//homepage
contact.BusinessHomePage = "n.a.";

// Specify the home address.
PhysicalAddressEntry paEntry1 = new PhysicalAddressEntry();
paEntry1.Street = "straße";
paEntry1.City = "stadt";
paEntry1.State = "D";
paEntry1.PostalCode = "88890";
paEntry1.CountryOrRegion = "Deutschland";
contact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry1;
contact.Save();

已经尝试过这个:

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test"); 


我用“test”和“test @ domain”和“test@domain.de”测试了它 并收回此错误:
“Der NamedesIdentitätsprinzipalsistungültig。” 自己的翻译:“身份证明的名称是公正的”

3 个答案:

答案 0 :(得分:0)

您可以像这样使用模拟

ExchangeUserData exchangeUserData = new ExchangeUserData();
exchangeUserData.Username = "c-sharp";
exchangeUserData.Password = "c-sharp"; // c-sharp's Password

ExchangeService service = Service.ConnectToServiceWithImpersonation(exchangeUserData, impersonatedUserPrincipal);

Contact contact = new Contact(service);

// Specify the name and how the contact should be filed.
contact.GivenName = "n.a.";
contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
contact.DisplayName = "bau gmbh";

// Specify the company name.
contact.CompanyName = "bau";

// Specify the business, home, and car phone numbers.
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "00000 00000";
contact.PhoneNumbers[PhoneNumberKey.MobilePhone] = "n.a.";
contact.PhoneNumbers[PhoneNumberKey.BusinessFax] = "00000 00000";

// Specify two email addresses.
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress("e@mail.de");

//homepage
contact.BusinessHomePage = "n.a.";

// Specify the home address.
PhysicalAddressEntry paEntry1 = new PhysicalAddressEntry();
paEntry1.Street = "straße";
paEntry1.City = "stadt";
paEntry1.State = "D";
paEntry1.PostalCode = "88890";
paEntry1.CountryOrRegion = "Deutschland";
contact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry1;
contact.Save();

答案 1 :(得分:0)

如果您的c-sharp用户在Exchange中拥有适当的权限,您应该可以:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials("c-sharp", "c-sharp", "domain");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test");

如果这不适合您,请在下方发表评论或更新您的问题(其下方有“编辑”链接),其中包含您看到的确切行为,包括任何错误消息。

答案 2 :(得分:0)

问题解决了。

我发现了这个错误......你们两个都是对的,只是改变了:

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test"); 

分为:

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "test@domain.de");

多数人......

非常感谢你