Outlook2003 inline image issue VC++

D

dorutzu

Hi,

I'm writing an Addin for Outlook in VC++ 6. The problem is that I
want to send an embeded image in my HTML format e-mail, and it's not
working. I had a great help in Neo's
article(http://www.outlookcode.com/d/code/htmlimg.htm), I transposed
it to VC++, but it's still not working (I get the image attached, a
nice red X instead of the image, and a new item in Drafts(BTW, how do
I avoid this?)). Could anyone help me out here? Thanks!

Here's the code (or part of it) :
//I have a brand new MailItem called spMailItem...
CComVariant vEntryID;
CComPtr<Outlook::Attachments> spAttachments;
HRESULT hr = spNewMail->get_Attachments(&spAttachments);

CComPtr<Outlook::Attachment> spAttach;
CComVariant vSource("C:\\Addin\\Test2.gif");
CComVariant vType(olByValue);
CComVariant vPos(1);
CComVariant vDispName("myindent");
hr = spAttachments->Add(vSource, vType, vPos, vDispName, &spAttach);

spNewMail->put_Subject(T2W("Test subj"));

spNewMail->Close(olSave);
spNewMail->get_EntryID(&vEntryID.bstrVal);
spNewMail.Release();
spAttach.Release();
delete spAttach;
spAttachments.Release();
delete spAttachments;


//the CDO part....
CComVariant comEntryID;
MAPI::_SessionPtr pMapiSession;
MAPI::MessagePtr pMapiMessage;
MAPI::AttachmentsPtr pMapiAttactments = NULL;
MAPI::AttachmentPtr pMapiAttactment = NULL;
MAPI::FieldsPtr pMapiFields;

pMapiSession.CreateInstance("MAPI.Session");
pMapiSession->Logon("Outlook");
CComVariant vEntryID2(vEntryID.bstrVal);
pMapiMessage = pMapiSession->GetMessage(vEntryID2);
pMapiAttactments = pMapiMessage->GetAttachments();
long lo = (long)pMapiAttactments->GetCount();
CComVariant v1(1);
pMapiAttactment = pMapiAttactments->GetItem((long)1);
CComVariant v(pMapiAttactment->Source); //this is strange - should be
"c:\Addin\Test2.gif"....but it's empty ""
pMapiFields = pMapiAttactment->GetFields();
MAPI::FieldPtr pMapiFld;
CComVariant vValue("image/gif");
pMapiFld = pMapiFields->Add((long)CdoPR_ATTACH_MIME_TAG, vValue);
CComVariant vMyIndent("myindent");
pMapiFld = pMapiFields->Add((long)0x3712001E, vMyIndent);
CComVariant vName3("{0820060000000000C000000000000046}0x8514");
pMapiFld = pMapiFields->Add(vName3, (long)11, true);
pMapiMessage->Update();
CComVariant vEntryID3(pMapiMessage->ID);

//back to Outlook
CComPtr<Outlook::_NameSpace> spNSmapi;
hr = m_spApp->GetNamespace(T2W("MAPI"), &spNSmapi);
CComPtr<IDispatch> spDispItem;
CComVariant vNull("");
spNSmapi->GetItemFromID(vEntryID3.bstrVal, vNull, &spDispItem);

CComQIPtr<Outlook::_MailItem> spNewMail2(spDispItem);

spNewMail2->put_BodyFormat(olFormatHTML); //html type
spNewMail2->put_HTMLBody(T2W("image here:<IMG align=baseline border=0
hspace=0 src=cid:myident>"));

spNewMail2->Display();
spNewMail2.Release();


Thanks for your time and pacience,
Doru
 
Joined
Dec 30, 2011
Messages
1
Reaction score
0
I used the following:
if(spMailItem)
{
CComPtr<outlook::Attachments> spAttachments;
HRESULT hRes = spMailItem->get_Attachments(&spAttachments);
if(SUCCEEDED(hRes) && spAttachments != NULL)
{
CComPtr<Attachment> spAttachment;
CComBSTR bstrFile(strFullSrc);
CComBSTR bstrFileName(strFileName);
CComVariant vtSource(bstrFile);
CComVariant vtType(olEmbeddeditem);
CComVariant vtPosition(i+1);
CComVariant vtDisplayName(strFileName);
spAttachments->Add(vtSource, vtType, vtPosition, vtDisplayName, &spAttachment);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

I finally did it 0

Top