簡體   English   中英

C#EWS將聯系人復制到郵箱

[英]C# EWS copy contacts to a mailbox

我想選擇用戶“ 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”對其進行了測試,然后返回此錯誤:
“識別名稱和名稱”。 自己的翻譯:“身份主體的名稱無效”

您可以像這樣使用模擬

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用戶在Exchange中擁有適當的權限,則您應該能夠:

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

進入:

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

就這樣 ...

非常感謝你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM