获取 Outlook 配置文件 MAPI 的电子邮件地址
Get email addresses of outlook profile, MAPI
如何使用
MAPI 从 Outlook 配置文件中获取电子邮件地址C++?启动代码(工作正常):
HRESULT hRes = S_OK;
LPMAPISESSION lpSession = NULL;
LPMDB lpMDB = NULL;
LPMAPITABLE lptMsgStores = NULL;
LPMAPITABLE spTable = NULL;
std::wstring wProfileName;
std::wstring wUsername;
wUsername = L"user1@mymail.com";
wProfileName = L"TestProfile";
// Initiate MAPI.
hRes = MAPIInitialize(0);
// Logon to Extended MAPI session.
hRes = MAPILogonEx(NULL,
(LPTSTR)wProfileName.c_str(),
NULL,
MAPI_EXTENDED | MAPI_EXPLICIT_PROFILE | MAPI_NEW_SESSION | MAPI_UNICODE | MAPI_LOGON_UI, &lpSession);
if(FAILED(hRes))
{
MessageBox(NULL,L"logon error", L"",MB_OK);
}
LPOLKACCOUNTMANAGER lpAcctMgr = NULL;
hRes = CoCreateInstance(CLSID_OlkAccountManager,
NULL,
CLSCTX_INPROC_SERVER,
IID_IOlkAccountManager,
(LPVOID*)&lpAcctMgr);
if(SUCCEEDED(hRes) && lpAcctMgr)
{
CAccountHelper *pMyAcctHelper = new CAccountHelper((LPWSTR)wProfileName.c_str(), lpSession);
if(pMyAcctHelper)
{
LPOLKACCOUNTHELPER lpAcctHelper = NULL;
hRes = pMyAcctHelper->QueryInterface(IID_IOlkAccountHelper, (LPVOID*)&lpAcctHelper);
if(SUCCEEDED(hRes) && lpAcctHelper)
{
LPOLKENUM lpAcctEnum = NULL;
hRes = lpAcctMgr->EnumerateAccounts(&CLSID_OlkMail,
NULL,
OLK_ACCOUNT_NO_FLAGS,
&lpAcctEnum); //THIS FAILS HERE, hRes != S_OK!
_com_error err(hRes);
LPCTSTR errMsg = err.ErrorMessage();
wprintf(L"%sn", errMsg);
if(SUCCEEDED(hRes) && lpAcctEnum)
{
DWORD cAccounts = 0 ;
hRes = lpAcctEnum->GetCount(&cAccounts);
if(SUCCEEDED(hRes))
{
hRes = lpAcctEnum->Reset();
if(SUCCEEDED(hRes))
{
DWORD i = 0;
for(i = 0 ; i< cAccounts; i++)
{
LPUNKNOWN lpUnk = NULL;
hRes = lpAcctEnum->GetNext(&lpUnk);
if(SUCCEEDED(hRes) &&lpUnk)
{
LPOLKACCOUNT lpAccount = NULL;
hRes = lpUnk->QueryInterface(IID_IOlkAccount, (LPVOID*)&lpAccount);
if(SUCCEEDED(hRes) && lpAccount)
{
ACCT_VARIANT pProp = {0};
HRESULT hRes = S_OK;
hRes = lpAccount->GetProp(PROP_ACCT_NAME, &pProp);
if(SUCCEEDED(hRes) && pProp.Val.pwsz)
{
wprintf(L"Found email:%sn", pProp.Val.pwsz);
lpAccount->FreeMemory((LPBYTE)pProp.Val.pwsz);
}
}
if(lpAccount)
lpAccount->Release();
lpAccount = NULL;
}
if(lpUnk)
lpUnk->Release();
lpUnk = NULL;
}
///////////
}
}
}
if(lpAcctEnum)
lpAcctEnum->Release();
}
}
if(pMyAcctHelper)
pMyAcctHelper->Release();
}
if(lpAcctMgr)
lpAcctMgr->Release();
// Release the session.
lpSession->Logoff(0,MAPI_LOGOFF_UI,0);
lpSession->Release();
MAPIUninitialize();
_getch();
您不会向配置文件添加电子邮件地址,而是添加可能 (POP3/IMAP4/SMTP) 或不 (PST) 公开或需要 SMTP 地址的服务。对于 POP3/IMAP4/SMTP 地址,请使用 IOlkAccountManager API。你可以在OutlookSpy中玩它(我是它的作者 - 点击IOlkAccountManager按钮)。
Outlook 对象模型通过 Namespace.Accounts 集合公开邮件帐户(仅邮件,而不是存储或通讯簿)。
相关文章:
- 尝试从C++访问 UWP 的电子邮件邮件类会导致"REGDB_E_CLASSNOTREG类未注册"错误
- 如何使HTML5电子邮件验证正则表达式在C++中工作?
- Qt:使用'mailto:'打开用户的电子邮件客户端失败
- 电子邮件地址中的c++smtp服务器主机名
- 如何使用 c++ (curl) 发送电子邮件
- 在端口 587 (TLS) 上使用 CDO 发送电子邮件时出错
- 预览由Microsoft Outlook 对象库生成的电子邮件
- 如果不有效,如何重复用户输入电子邮件
- 使用REGEX进行电子邮件输入验证C
- 如何从 pjsip 发送电子邮件.是否有任何可用于发送电子邮件的默认方法
- 如何在使用 c++/COM 发送时在电子邮件中插入/嵌入图像文件(.png)
- 如何提示用户在C++中输入正确的电子邮件地址格式
- 如何使用MAPI从配置文件中获取电子邮件地址
- Boost Spirit电子邮件地址解析器属性生成
- 验证电子邮件地址和地址中的句点数
- 获取 Outlook 配置文件 MAPI 的电子邮件地址
- 在电子邮件地址内移动点(句点)的算法
- 伪电子邮件地址和电子邮件解析器
- Outlook -从显示名称获取电子邮件地址.可以在Python中工作,而不是C
- 使用Mapi发送邮件并回复多封电子邮件