检索通过OLE连接后Outlook登录的用户SMTP地址



Exchange Web Services有一个ResolveNames()函数,我可以使用它来检索(除其他外)通过EWS登录到Exchange Server的Active Directory用户的主SMTP地址。

我现在正在通过OLE针对Outlook进行编程,并希望获得相同的功能。

我一直在浏览Outlook对象模型,但找不到合适的对象或方法

有人知道我可以用来获取主SMTP地址的对象/方法吗?

下面是我用来连接到Outlook的当前Delphi代码
对于默认登录的用户(AUserSMTP="),它返回OutlookApp COM对象(通过GetActiveOleObject或CreateOleObject)、NameSpace(通过GetNameSpace)和Folder(通过GetDefaultFolder)对象,但我找不到从那里开始的位置
我认为lNameSpace.CurrentUser(一个Recipient对象)可能会有所帮助,但它的Address属性只返回一个字符串,如'/o=TimeTell/ou=Exchange管理组(FYDIBOHF23SPDLT)/cn=Recipients/cn=developer',而没有电子邮件地址。。。

关于要走的路线有什么建议吗?

function TDataModuleSyncOutlook.ConnectToOutlook(AUserSMTP: String = ''): Boolean;
var
   lNameSpace, lRecipient: OleVariant;
begin
   Result      := false;
   FWasCreated := False;  
   try
      FOutlookApp := GetActiveOleObject(scxOutlookApp);
      Result := True;
   except
      try
         FOutlookApp := CreateOleObject(scxOutlookApp);
         FWasCreated := True;
         Result := True;
      except
         on E:Exception do ...
      end;
   end;
   if Result then      
   begin
      lNameSpace := FOutlookApp.GetNameSpace(scxNameSpace);
      if AUserSMTP <> '' then   // This part not applicable to the question   
      begin   // Open shared calendar als er een expliciete gebruiker is opgegeven...
         lRecipient := lNameSpace.CreateRecipient(AUserSMTP);
         try
            FCalendarFolder := lNameSpace.GetSharedDefaultFolder(lRecipient, olFolderCalendar);
         except
            on E:Exception do ...
         end;
      end
      else   // ... anders de default calendar folder openen
         FCalendarFolder := lNameSpace.GetDefaultFolder(olFolderCalendar);
   end;
   FOleInitialized := Result;
   if Result then TSyncLogger.LogAlways('Connected to Outlook') else TSyncLogger.LogAlways('Connection to Outlook failed');
end;

尝试使用Application.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress(当然需要检查null)。

至于帐户顺序,您可以使用Extended MAPI和IOlkAccountManager.GetOrder(如果单击IOlkAccountManager按钮,您可以在OutlookSpy中玩该对象(我是其作者)),也可以使用Redemption(我也是其作者)及其RDOSession.Accounts.GetOrder方法(请参阅http://www.dimastr.com/redemption/RDOAccounts.htm)。返回集合中的第一个帐户将是默认帐户。

我找到了它。我必须遍历命名空间中的Accounts对象:

for i := 1 to lNameSpace.Accounts.Count do
   if lNameSpace.Accounts.Item[i].AccountType = olExchange then
   begin
      lAccount := lNameSpace.Accounts.Item[i];
      Break;
   end;
if VarIsClear(lAccount) then
begin
   DisConnectFromOutlook;
   Exit;
end;
lLoginSMTP := lAccount.SmtpAddress;

我唯一想做的就是确定默认帐户。

最新更新