HRESULT hr;
CComPtr<Outlook::_NameSpace> spSession = NULL;
hr = m_spExplorer->get_Session(&spSession);
ATLASSERT(spSession);
CComPtr<Outlook::MAPIFolder> spMPFolder = NULL;
hr = spSession->GetDefaultFolder(Outlook::olFolderOutbox, &spMPFolder);
ATLASSERT(spMPFolder);
CComPtr<Outlook::_Items> spItems = NULL;
spMPFolder->get_Items(&spItems);
long lCount = 0;
spItems->get_Count(&lCount);
for(long i = 1; i <= lCount; i++)
{
VARIANT var;
var.vt = VT_I4;
var.lVal = i;
IDispatch *pItem = NULL;
spItems->Item(var, &pItem);
Outlook::_MailItem* pMailItem = (Outlook::_MailItem*)(pItem);
CComPtr<Outlook::Attachments> spAttachments = NULL;
pMailItem->get_Attachments(&spAttachments);
long l = 0;
spAttachments->get_Count(&l);
for (long j = 1; j <= l; j++)
{
VARIANT varAt;
varAt.vt = VT_I4;
varAt.lVal = j;
CComPtr<Outlook::Attachment> spAttachment = NULL;
spAttachments->Item(varAt, &spAttachment);
BSTR strAtName;
spAttachment->get_FileName(&strAtName);
//spAttachment->SaveAsFile(L"C:\\"+ strAtName);
}
}
COM实现读取outlook附件代码片段
最新推荐文章于 2023-03-25 22:50:43 发布