【问题标题】:The account does not have permission to impersonate the requested user while saving appointment on other user's outlook calendar该帐户无权在其他用户的 Outlook 日历上保存约会时模拟请求的用户
【发布时间】:2017-01-06 17:18:32
【问题描述】:

我想使用 EWS 在 Outlook 日历上创建约会。我关注了https://msdn.microsoft.com/en-us/library/office/dn722379(v=exchg.150).aspx 链接。但我看到了这个错误:

“该帐户无权模拟请求的用户”。

请查看我的代码

private static ExchangeService Service
    {
        get
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
            //service.Credentials = new WebCredentials("example@abc.com", password);
            service.AutodiscoverUrl("example@abc.com");
            return service;
        }
    }

private void SaveAppointment()
{
        IAppointmentFactory iappointment = new AppointmentFactory();
        List<string> lstEmail = new List<string>() {"other@abc.com"};

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

【问题讨论】:

  • 您是否在 Google 上搜索了该问题,然后选择了第一个结果? stackoverflow.com/questions/15204411/…
  • 是的,我已经浏览了这个链接,但不明白在哪里将该代码修复到我的代码中。你能推荐一下吗?

标签: c# exchangewebservices


【解决方案1】:

您似乎只有对日历的委托访问权限,因此您希望将约会保存到。

为了让您的代码正常工作,请删除该行

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

并像这样更改Save 方法:

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

【讨论】:

  • 嗨特里斯坦,感谢您的回复。我已经按照你的建议做了同样的事情。上述问题现在解决了,但又出现了一个新问题,即“在商店中找不到指定的文件夹”。你对这个问题有什么想法吗?
  • 这个问题很可能是由授权问题引起的。您确定您已被授予对您想要保存约会的所有邮箱/日历的代理访问权限吗?您可以通过执行DelegateInformation result = service.GetDelegates(new Mailbox("emailAddress"), true); 并将result 打印到您的控制台或其他地方来了解这一点。
  • 我写了那行代码,但是在 DelegateInformation result = service.GetDelegates(new Mailbox(emailAddress), true);行。
  • 好的,请问您的系统管理员是否有指定邮箱的代理访问权限?如有必要,他可以将它们授予您。
  • 感谢您的回复 :)。
猜你喜欢
  • 2013-02-18
  • 1970-01-01
  • 2021-01-28
  • 2016-06-28
  • 1970-01-01
  • 2016-10-31
  • 1970-01-01
  • 2014-10-11
  • 1970-01-01
相关资源
最近更新 更多