C# 使用EWS创建约会时出现异常
我在使用我的服务EWS时遇到异常,这是我的代码C# 使用EWS创建约会时出现异常,c#,exchangewebservices,C#,Exchangewebservices,我在使用我的服务EWS时遇到异常,这是我的代码 public class ExchangeHelper { ExchangeService exchangeService; public ExchangeHelper() { //Instantiate a new ExchangeService object exchangeService = new ExchangeService(ExchangeVersion.Exchange201
public class ExchangeHelper
{
ExchangeService exchangeService;
public ExchangeHelper()
{
//Instantiate a new ExchangeService object
exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
//Set the exchange WebService URL
exchangeService.Url = new Uri("https://hostname/EWS/Exchange.asmx");
//exchangeService.Url = new Uri("https://hostname/EWS/Exchange.asmx");
//Set the credentials of the service to the credentials
//that are associated with the impersonating account.
exchangeService.Credentials = new NetworkCredential(
"user",
"pass",
"Domain.com"
);
}
public void CreateAppointment()
{
var emailAddress = "user@doamin.com";
//Set the ImpersonatedUserId property of the ExchangeService object to identify the impersonated user (target account).
//This example uses the user's SMTP email address.
exchangeService.AutodiscoverUrl(emailAddress);
exchangeService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailAddress);
//create a new appointment object
Appointment appointment = new Appointment(exchangeService);
//set appointment properties
appointment.Subject = "test";
appointment.Body = "testBody";
//In MSDN it says that if you dont specify the timezone, it will use the UTC timezone
//but in reality it is not working that way.
//so explicity setting the EST timezone
appointment.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
appointment.Start = DateTime.Now;
appointment.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
appointment.End = DateTime.Now.AddHours(1);
//add required participants
appointment.RequiredAttendees.Add(emailAddress);
newFolder.Save(WellKnownFolderName.Inbox);
appointment.Save(new FolderId(WellKnownFolderName.Drafts, "emailAddress"));
//Set it back to null so that any actions that will be taken using the exchange service
//applies to impersonating account (i.e.account used in network credentials)
exchangeService.ImpersonatedUserId = null;
return the unique identifier that is created
return appointment.Id.UniqueId;
}
例外情况是“该帐户没有模拟请求用户的权限”从您的帖子中无法100%清楚您用于ExchangeService上的凭据和用于模拟用户ID的帐户是否相同。如果是,则不需要使用模拟,也不应设置该属性。似乎一个人应该能够模仿自己,但没有必要这样做,因此EWS可能会把你扔回那个例外 如果它们是不同的,那么这就像消息所说的:您用于凭据的帐户必须有权模拟您设置的用户。这通常需要Exchange管理员使用一些PowerShell魔法来设置