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
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