从Outlook电子邮件中获取附件 [英] Get back an attachment from an Outlook email
问题描述
您好,我想检索特定的电子邮件附件。
例如,电子邮件"E"有4个附件,我想要获得第三个。
我正在使用C ++应用程序并与我的Outlook(2013)应用程序进行通信我正在使用
AutoWrap( )方法(使用C ++进行MS Office OLE自动化 - http://www.codeproject.com/Articles/34998/MS-Office-OLE-Automation-Using-C)。
<我已经阅读了Outlook对象模型文档(http://msdn.microsoft.com/en-us/library/office/ff862684%28v=office.15%29.aspx),但我无法解决我的问题。
问题是我无法从我用来取回特定附件项的AutoWrap方法中找回一个好的HRESULT值。
以下是代码:
...我们不关心的一些代码......
VARIANT结果;
VariantInit(& result);
HRESULT hRes = S_OK;
&NBSP;但是CComPtr< IDispatch的> pAttachments; //电子邮件附件
HRESULT hRes = AutoWrap(DISPATCH_PROPERTYGET,& result,pOfficeItem,L" Attachments",0);
if(!result.pdispVal || FAILED(hRes))返回EditorError; //其中EditorError是一个枚举
pAttachments = result.pdispVal;
VariantInit(& result);
hRes = AutoWrap(DISPATCH_PROPERTYGET,& result,pAttachments,L" Count",0);
if(FAILED(hRes))返回EditorError;
int aNumber = result.iVal; //它有效...如果所研究的电子邮件有4个附件,那么'aNumber'是4
if(aNumber> 0)//如果电子邮件包含附件
{
for(int i = 0; i< aNumber; i ++)for each attachment
&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; VARIANT attachmentIndex;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; attachmentIndex.intVal = VT_INT;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; attachmentIndex.iVal = i;
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; VariantInit(& result);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;但是CComPtr< IDispatch的> pAttachmentItem;
//我已经尝试了以下所有说明,但没有人解决我的问题
//'pOfficeItem'是指向实际Outllok项目的一个很好的指针(我确定这不是我的问题,它在我工作的所有其他部分都可以正常工作)
;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; hRes = AutoWrap(DISPATCH_METHOD,& result,pOfficeItem,L" Attachments",1,attachmentIndex);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP; HRES = AutoWrap(DISPATCH_PROPERTYGET,&安培;结果,pOfficeItem,L"附件",1,attachmentIndex);
&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; hRes = AutoWrap(DISPATCH_METHOD,& result,pAttachments,L" Item",1,attachmentIndex);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; hRes = AutoWrap(DISPATCH_PROPERTYGET,& result,pAttachments,L" Item",1,attachmentIndex);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP; HRES = AutoWrap(DISPATCH_METHOD,&安培;结果,pOfficeItem,L" Attachments.Item",1,attachmentIndex);
&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP; HRES = AutoWrap(DISPATCH_PROPERTYGET,&安培;结果,pOfficeItem,L" Attachments.Item",1,attachmentIndex);
&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; hRes = AutoWrap(DISPATCH_METHOD,& result,pAttachments,L" Attachments.Item",1,attachmentIndex);
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP; HRES = AutoWrap(DISPATCH_PROPERTYGET,&安培;结果,pAttachments,L" Attachments.Item",1,attachmentIndex);
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; if(FAILED(hRes))//这是我的问题,总是返回EditoError !!!
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; 返回EditorError;
pAttachmentItem = result.pdispVal;
......与附件一起做... ...
我在这个领域很新,所以你的意见/答案将不胜感激。
谢谢你,Pie
Hello Pie,
为什么需要使用AutoWrap方法?
参见
C ++应用程序自动化Outlook(CppAutomateOutlook)。您还可以找到
如何使用Visual C ++ / MFC自动化Outlook
文章有用。
Hello, I would like to retrieve back a specific email attachment.
For example the email 'E' has 4 attachments and I want to get the 3rd one.
I'm working using a C++ application and to communicate with my Outlook (2013) application I'm using the AutoWrap() method ( MS Office OLE Automation Using C++ - http://www.codeproject.com/Articles/34998/MS-Office-OLE-Automation-Using-C).
I've read the Outlook Object Model documentation (http://msdn.microsoft.com/en-us/library/office/ff862684%28v=office.15%29.aspx) but I'm not able to solve my problem.
The problem is that I can't get back a good HRESULT value from the AutoWrap method I use to get back the specific attachment item.
Here is the code:
... SOME CODE WE DON'T CARE ...
VARIANT result;
VariantInit(&result);
HRESULT hRes= S_OK;
CComPtr<IDispatch> pAttachments; // email attachments
HRESULT hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pOfficeItem, L"Attachments", 0);
if (!result.pdispVal || FAILED(hRes)) return EditorError; // where EditorError is an Enum
pAttachments = result.pdispVal;
VariantInit(&result);
hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pAttachments, L"Count", 0);
if (FAILED(hRes)) return EditorError;
int aNumber = result.iVal; // it works... if the studied email has 4 attachments then 'aNumber' is 4
if (aNumber > 0) // if the Email contains attachments
{
for (int i = 0; i < aNumber; i++) for each attachment
{
VARIANT attachmentIndex;
attachmentIndex.intVal = VT_INT;
attachmentIndex.iVal = i;
VariantInit(&result);
CComPtr<IDispatch> pAttachmentItem;
// I've tried all the following instructions but no one solves my problem
// 'pOfficeItem' is a good pointer to the actual Outllok item (I'm sure it is not my problem, it works fine in all other parts of my work)
hRes = AutoWrap(DISPATCH_METHOD, &result, pOfficeItem, L"Attachments", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pOfficeItem, L"Attachments", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_METHOD, &result, pAttachments, L"Item", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pAttachments, L"Item", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_METHOD, &result, pOfficeItem, L"Attachments.Item", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pOfficeItem, L"Attachments.Item", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_METHOD, &result, pAttachments, L"Attachments.Item", 1, attachmentIndex);
hRes = AutoWrap(DISPATCH_PROPERTYGET, &result, pAttachments, L"Attachments.Item", 1, attachmentIndex);
if (FAILED(hRes)) // here is my problem, EditoError is always returned!!!
return EditorError;
pAttachmentItem = result.pdispVal;
... DO SOMETHING WITH THE ATTACHMENT ...
I'm pretty new in this field so your comments/answers will be appreciated.
Thank you, Pie
Hello Pie,
Why do you need to use the AutoWrap method?
See C++ app automates Outlook (CppAutomateOutlook) . Also you may find the How To Automate Outlook Using Visual C++/MFC article helpful.
这篇关于从Outlook电子邮件中获取附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!