设为首页 收藏本站
查看: 1171|回复: 0

[经验分享] 如何获取outlook的参会人列表

[复制链接]
累计签到:8 天
连续签到:1 天
发表于 2015-9-13 11:16:10 | 显示全部楼层 |阅读模式
  如何获取一个outlook参会人的具体地址呢,我们要用到Outlook::Recipient这个对象,主要是用它的get_Address方法来获得参会人的邮件地址,这个很简单。麻烦的是对于exchange服务器,对exchange服务器来说,如果遇到ad域的情况,那么用get_Address获取到的,就不是正常的邮件地址,而是ad域在exchange中计算地址的字符串,例如/o=Organization/ou=First Administrative Group。
  对于上述的ad域情况,又分好几种情况,这主要取决于Outlook::AddressEntry这个对象,AddressEntry有个OlAddressEntryUserType属性,是个枚举类型,定义如下:
  enum OlAddressEntryUserType
  {
  olExchangeUserAddressEntry = 0,
  olExchangeDistributionListAddressEntry = 1,
  olExchangePublicFolderAddressEntry = 2,
  olExchangeAgentAddressEntry = 3,
  olExchangeOrganizationAddressEntry = 4,
  olExchangeRemoteUserAddressEntry = 5,
  olOutlookContactAddressEntry = 10,
  olOutlookDistributionListAddressEntry = 11,
  olLdapAddressEntry = 20,
  olSmtpAddressEntry = 30,
  olOtherAddressEntry = 40
  };
      我们遇到最多的是olExchangeUserAddressEntry和olExchangeDistributionListAddressEntry,这两个可以用对应的api函数get_PrimarySmtpAddress可以获得地址,其它的smtp的不用考虑,统一用get_Address来获取地址;我遇到过一种olExchangeAgentAddressEntry类型的,不能用api来获取,后来反复测试确认,最后用的是GetProperty来拿到地址的。

      OlAddressEntryUserType中剩余的类型我没遇到过,估计大部分也可以用get_PrimarySmtpAddress来获取,如果不能,就只能用GetProperty来了,个人觉得这个函数是万能的,只要你能拿到对应属性的tag。

      以下是该函数的代码:




void GetRecipientMails(CComQIPtr<Outlook::_AppointmentItem> &spApptmt)
{
CString strMails;
BSTR bstrRcvMail = NULL;                            // 保存参会人邮箱
// 保存主持人邮箱
CComPtr<Outlook::Recipients> spRcvPns;                // 所有参会人
CComPtr<Outlook::Recipient> spRcvPn;                // 一个参会人
CComPtr<Outlook::_NameSpace> spNameSpace;
CComPtr<Outlook::Recipient> spCrrentRcvPn;            // 当前outlook用户
CComPtr<Outlook::UserProperties> spUserPro;
CString strRcvMails;
spApptmt->get_Recipients(&spRcvPns);
// 这个m_spApplication是个成员变量,表示一个outlook的application句柄,需要从别处获取
    // 或者就用_AppointmentItem的get_Application来获取,我这里因为是现成的,所以直接用了
m_spApplication->GetNamespace(L"MAPI",&spNameSpace);
if (NULL != spRcvPns)
{
long lNum = 0;                            // 参会人个数
spRcvPns->get_Count(&lNum);
m_lMailCount = lNum;
VARIANT vIndex;                        
vIndex.vt = VT_I4;                        
for (long i = 1; i <= lNum; i++)        // 这vIndex必须从1开始
        {
vIndex.lVal = i;
spRcvPns->Item(vIndex,&spRcvPn);
if (NULL != spRcvPn)
{
CComQIPtr<Outlook::AddressEntry> spAddEntry;
CComQIPtr<Outlook::AddressEntry> spAddEntryBuffer;
OlAddressEntryUserType OlAddEntryUserType;
CComQIPtr<Outlook::_ExchangeUser> spExchangeUser;
spRcvPn->get_AddressEntry(&spAddEntry);
// 获取entrytype类型
BSTR bstrType = NULL;
spAddEntry->get_Type(&bstrType);
CString strEntryType(bstrType);
SysFreeString(bstrType);

// OlAddressEntryUserType特性是在2007开始添加的,如果是2003去获取,此处会崩溃退出。
// 非2003版本
if (!m_bOffice2k3OrBefore)
{
// 获取entryusertype类型
spAddEntry->get_AddressEntryUserType(&OlAddEntryUserType);
CString strEntryUserType;
strEntryUserType.Format(L"OlAddEntryUserType is %d", OlAddEntryUserType);
if (!strEntryType.Compare(L"EX"))
{
BSTR bstrEntryID = NULL;
spRcvPn->get_EntryID(&bstrEntryID);                    
// 作为olExchangeAgentAddressEntry的地址条目
if (OlAddEntryUserType == olExchangeAgentAddressEntry)
{
CComQIPtr<Outlook::_PropertyAccessor> spPropAccessor;
spAddEntry->get_PropertyAccessor(&spPropAccessor);
if (NULL != spPropAccessor)
{
CComVariant varAgentAddress = (L"");
BSTR bstrPropName = SysAllocString(L"http://schemas.microsoft.com/mapi/proptag/0x39FE001E");
HRESULT hr = spPropAccessor->GetProperty(bstrPropName, &varAgentAddress);
if (S_OK == hr)
{
CString strAddress = varAgentAddress.bstrVal;
bstrRcvMail = varAgentAddress.bstrVal;
}
SysFreeString(bstrPropName);
}
}
// 作为非Exchange通讯组列表的地址条目
else if (OlAddEntryUserType != olExchangeDistributionListAddressEntry)
{
spNameSpace->GetAddressEntryFromID(bstrEntryID,&spAddEntryBuffer);
spAddEntryBuffer->GetExchangeUser(&spExchangeUser);
spExchangeUser->get_PrimarySmtpAddress(&bstrRcvMail);                           
}
// 作为Exchange通讯组列表的地址条目
else
{
spNameSpace->GetAddressEntryFromID(bstrEntryID,&spAddEntryBuffer);
CComQIPtr<Outlook::_ExchangeDistributionList> spExchangeDisList;
spAddEntryBuffer->GetExchangeDistributionList(&spExchangeDisList);
spExchangeDisList->get_PrimarySmtpAddress(&bstrRcvMail);
}
}
else
{
spRcvPn->get_Address(&bstrRcvMail);   
}
}
// 2003版本
else
{
spRcvPn->get_Address(&bstrRcvMail);
}
strMails += bstrRcvMail;
strMails += L";";
SysFreeString(bstrRcvMail);
}
spRcvPn = NULL;               
}
}

}
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112977-1-1.html 上篇帖子: 监听outlook新邮件 下篇帖子: VBA outLook
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表