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

C#EWS将联系人复制到邮箱,c#,exchange-server,exchangewebservices,C#,Exchange Server,Exchangewebservices,我想选择用户“test”,以便在他的邮箱中创建联系人 我的实际问题是,它会在我的用户“c-sharp”中创建联系人 “c-sharp”对“测试”邮箱具有完全访问权限 我更改了IP和联系人信息,用户也仅用于测试 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013); service.TraceEnabled = true; service.TraceFlags = TraceFlags.All; se

我想选择用户“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@domain“和”test@domain.de" 并返回此错误:
“身份识别者的名字是ungültig。”
自己的翻译:“身份主体的名称未失效”

您可以像这样使用模拟

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();

如果您的
c-sharp
用户拥有相应的交换权限,您应该能够:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials("c-sharp", "c-sharp", "domain");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test");
如果这对您不起作用,请在下面发表评论,或用您看到的确切行为(包括任何错误消息)更新您的问题(下面有一个“编辑”链接)。

问题已解决

我发现了窃听器。。。你们都是对的,只要改变一下:

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

就这些


非常感谢您

这不起作用,因为无法使用exchange用户数据
exchangeUserData exchangeUserData=新的exchangeUserData();exchangeUserData.Username=“c-sharp”;exchangeUserData.Password=“c-sharp”//c-sharp的密码ExchangeService service=service.ConnectToServiceWithImpersonation(exchangeUserData,impersonatedUserPrincipal);请比“这不起作用”更具体。当你尝试安德烈亚斯的建议时会发生什么?你收到错误信息了吗?如果是:错误消息是什么?
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "test@domain.de");