通过 OLE 连接后检索 Outlook 登录用户的 SMTP 地址 [英] Retrieve Outlook logged-in user SMTP address after connecting through OLE

查看:13
本文介绍了通过 OLE 连接后检索 Outlook 登录用户的 SMTP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Exchange 网络服务 有一个 ResolveNames() 可用于检索(除其他外)通过 EWS 登录到 Exchange Server 的 Active Directory 用户的主 SMTP 地址的功能.

Exchange Web Services has a ResolveNames() function that I can use to retrieve (among other things) the primary SMTP address for the Active Directory user that logged on to Exchange Server through EWS.

我现在正在通过 OLE 对 Outlook 进行编程,并且想要相同的功能.

I am now programming through OLE against Outlook and would like the same functionality.

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

I have been browsing through the Outlook object model but can't find an appropriate object or method.

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

Does anyone know of an object/method that I can use to get the primary SMTP address?

以下是我用来连接到 Outlook 的当前 Delphi 代码.
对于登录的默认用户 (AUserSMTP=''),它返回 OutlookApp COM 对象(通过 GetActiveOleObject 或 CreateOleObject),一个 NameSpace(通过 GetNameSpace)和 文件夹(通过 GetDefaultFolder)对象,但我找不到从那里去哪里.
我认为 lNameSpace.CurrentUser (a 收件人对象) 可能会指向某个地方,但它的 Address 属性只返回一个类似 '/o=TimeTell/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=developer' 的字符串,没有电子邮件地址...

Below is the current Delphi code that I use to connect to Outlook.
For the default user logging in (AUserSMTP='') it returns the OutlookApp COM Object (through GetActiveOleObject or CreateOleObject), a NameSpace (through GetNameSpace) and a Folder (through GetDefaultFolder) object, but I could not find where to go from there.
I thought lNameSpace.CurrentUser (a Recipient object) might lead somewhere, but its Address property only returns a string like '/o=TimeTell/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=developer' without email address...

对路线有什么建议吗?

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(您当然需要检查空值)?

Why not use Application.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress (you would of course need to check for nulls)?

至于帐户顺序,您可以使用扩展 MAPI 和 IOlkAccountManager.GetOrder(您可以在 OutlookSpy(如果您单击 IOlkAccountManager 按钮)或者您可以使用 Redemption 及其 RDOSession.Accounts.GetOrder 方法(参见 http://www.dimastr.com/redemption/RDOAccounts.htm).返回集合中的第一个帐户将是默认帐户.

As for the account order, you can either use Extended MAPI and IOlkAccountManager.GetOrder (you can play with that object in OutlookSpy if you click IOlkAccountManager button) or you can use Redemption and its RDOSession.Accounts.GetOrder method (see http://www.dimastr.com/redemption/RDOAccounts.htm). The first account in the returned collection will be the default one.

这篇关于通过 OLE 连接后检索 Outlook 登录用户的 SMTP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆