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

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

问题描述

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



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



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



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



以下是我用来连接到Outlook的当前Delphi代码。

对于默认用户登录(AUserSMTP =')返回OutlookApp COM对象(通过GetActiveOleObject或CreateOleObject),一个 NameSpace (通过GetNameSpace)和一个文件夹(通过GetDefaultFolder)对象,但我找不到从那里去哪里。

我以为lNameSpace.CurrentUser(a 收件人对象)可能会导致某个地方,但其仅地址属性返回一个字符串,如'/ o = TimeTell / ou = Exchange管理组(FYDIBOHF23SPDLT)/ cn =收件人/ cn =开发人员没有电子邮件地址...



关于路由的任何建议?

 函数TDataModuleSyncOutlook.ConnectToOutlook(AUserSMTP:String =''):布尔值
var
lNameSpace,lRecipient:OleVariant;
begin
结果:= false;
FWasCreated:= False;
try
FOutlookApp:= GetActiveOleObject(scxOutlookApp);
结果:= True;
除了
尝试
FOutlookApp:= CreateOleObject(scxOutlookApp);
FWasCreated:= True;
结果:=真;
除了
对于E:Exception do ...
end;
结束
如果结果然后
开始
lNameSpace:= FOutlookApp.GetNameSpace(scxNameSpace);
如果AUserSMTP<> ''然后//这部分不适用于问题
开始//打开共享日历als er een expliciete gebruiker是opgegeven ...
lRecipient:= lNameSpace.CreateRecipient(AUserSMTP);
try
FCalendarFolder:= lNameSpace.GetSharedDefaultFolder(lRecipient,olFolderCalendar);
除了
对于E:Exception do ...
end;
end
else // ... anders de default calendar folder openen
FCalendarFolder:= lNameSpace.GetDefaultFolder(olFolderCalendar);
结束
FOleInitialized:= Result;
如果结果,则TSyncLogger.LogAlways('连接到Outlook')否则TSyncLogger.LogAlways(连接到Outlook失败);
结束


解决方案

为什么不使用Application.Session.CurrentUser.AddressEntry。 GetExchangeUser.PrimarySmtpAddress(你当然需要检查null)?



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


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.

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

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

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

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...

Any suggestions about the route to take?

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;

解决方案

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

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天全站免登陆