2017-01-06 11 views
0

EWSを使用してOutlook予定表に予定を作成します。私はhttps://msdn.microsoft.com/en-us/library/office/dn722379(v=exchg.150).aspxリンクに続いた。しかし、私はこのエラーを見ています:他のユーザーの予定カレンダーに予定を保存している間、アカウントに要求されたユーザーを偽装する権限がありません

"The account does not have permission to impersonate the requested user".

私のコードを

private static ExchangeService Service 
    { 
     get 
     { 
      ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); 
      //service.Credentials = new WebCredentials("[email protected]", password); 
      service.AutodiscoverUrl("[email protected]"); 
      return service; 
     } 
    } 

private void SaveAppointment() 
{ 
     IAppointmentFactory iappointment = new AppointmentFactory(); 
     List<string> lstEmail = new List<string>() {"[email protected]"}; 

     CreateAppointments(Service, lstEmail, iappointment); 
} 

private static void CreateAppointments(ExchangeService service, List<string> emailAddresses, IAppointmentFactory factory) 
{ 
    // Loop through the list of email addresses to add the appointment. 
    foreach (var emailAddress in emailAddresses) 
    { 
     Console.WriteLine(string.Format(" Placing appointment in calendar for {0}.", emailAddress)); 

     // Set the email address of the account to get the appointment. 
     service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailAddress); 

     // Get the appointment to add. 
     Microsoft.Exchange.WebServices.Data.Appointment appointment = factory.GetAppointment(service); 

     // Save the appointment. 
     try 
     { 
      if (appointment.RequiredAttendees.Count > 0) 
      { 
       // The appointment has attendees so send them the meeting request. 
       appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy); 
      } 
      else 
      { 
       // The appointment does not have attendees, so just save to calendar. 
       appointment.Save(SendInvitationsMode.SendToNone); 
      } 
     } 
     catch (ServiceResponseException ex) 
     { 
      Console.WriteLine(string.Format("Could not create appointment for {0}", emailAddress)); 
      Console.WriteLine(ex.Message); 
     } 
    } 
} 
+1

を、あなたはこの問題をグーグルしてから最初の結果を選択しましたか? http://stackoverflow.com/questions/15204411/the-account-does-not-have-permission-to-impersonate-the-requested-user – Bassie

+0

はい、私はすでにこのリンクに行きましたが、理解できませんでした。そのコードを自分のコードに修正してください。あなたはお勧めできますか? – manika

答えて

1

を行ってくださいあなたが唯一のカレンダーへの代理人アクセスを持っているとして、あなたはに予定を保存したいようです。

あなたのコードの作業を取得するためには、

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailAddress); 

行を削除して、このようなSave方法に変更してください:

appointment.Save(new FolderId(WellKnownFolderName.Calendar, new Mailbox(emailAddress)), SendInvitationsMode.SendOnlyToAllAndSaveCopy); 
+0

こんにちはトリスタン、ご返信ありがとうございます。私はあなたが提案したのと同じことをした。上記の問題は解決しましたが、「指定されたフォルダがストアに見つかりませんでした」という新しい問題が発生します。この問題についてお考えですか? – manika

+0

この問題は、認証の問題が原因と考えられます。予定を保存するすべてのメールボックス/カレンダーに代理人アクセス権が与えられていますか?これについては、 'DelegateInformation result = service.GetDelegates(new Mailbox(" emailAddress ")、true);'を実行し、 'result'をコンソールや他の場所に出力することで調べることができます。 – NotTelling

+0

私はそのコード行を書きましたが、DelegateInformation result = service.GetDelegates(new Mailbox(emailAddress)、true)に対して同じ例外を与えています。ライン。 – manika

関連する問題