COM实现读取outlook附件代码片段

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); 
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值