Пример #1
1
        public static ExchangeService ConnectToServiceWithImpersonation(
      IUserData userData,
      string impersonatedUserSMTPAddress,
      ITraceListener listener)
        {
            ExchangeService service = new ExchangeService(userData.Version);

              if (listener != null)
              {
            service.TraceListener = listener;
            service.TraceFlags = TraceFlags.All;
            service.TraceEnabled = true;
              }

              service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password);

              ImpersonatedUserId impersonatedUserId =
            new ImpersonatedUserId(ConnectingIdType.SmtpAddress, impersonatedUserSMTPAddress);

              service.ImpersonatedUserId = impersonatedUserId;

              if (userData.AutodiscoverUrl == null)
              {
            service.AutodiscoverUrl(userData.EmailAddress, RedirectionUrlValidationCallback);
            userData.AutodiscoverUrl = service.Url;
              }
              else
              {
            service.Url = userData.AutodiscoverUrl;
              }

              return service;
        }
Пример #2
0
 public void SetConnectMailbox(string currentMailbox)
 {
     if (currentMailbox.ToLower() != ServiceCredential.UserName.ToLower())
     {
         ServiceEmailAddress = currentMailbox;
         UserToImpersonate = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, currentMailbox);
         SetXAnchorMailbox = true;
         XAnchorMailbox = currentMailbox;
     }
     else
     {
         if(UserToImpersonate != null)
         {
             UserToImpersonate = null;
             SetXAnchorMailbox = false;
             XAnchorMailbox = string.Empty;
         }
         ServiceEmailAddress = currentMailbox;
     }
 }
Пример #3
0
 private ExchangeService CreateImpersonatedService(ImpersonatedUserId UserId,ExchangeCredentials exchangeCredentials)
 {
     return new ExchangeService(this.exchangeVersion) { Credentials = exchangeCredentials, ImpersonatedUserId=UserId };
 }