M
_maximus_
Hello All,
I am trying to translate in C++ example of embedding images in htm
mailitem from http://www.outlookcode.com/d/formatmsg.htm
but a bit different - using Redemption.
It seems very strange that I have exception in last code line.
Has anybody tried to accomplish similar task?
Thanks.
Code
-------------------
std::wstring installDir = settingsDlg.GetInstallDirectory();
std::wofstream debug((const char*)(installDir + _T("debug")).c_str());
CComPtr<Outlook::_MailItem> item;
m_spApp->CreateItem(olMailItem, (IDispatch**)&item);
item->put_To(email.bstrVal);
CComPtr<Outlook::Attachments> attachs;
item->get_Attachments(&attachs);
CComPtr<Outlook::Attachment> attach;
HRESULT hr = attachs->Add(_variant_t((installDir + std::wstring(_T("LOGO.jpg"))).c_str()), vtMissing, vtMissing, vtMissing, &attach);
item->Close(olSave);
item->Save();
CComBSTR entryID;
item->get_EntryID(&entryID);
attach.Release();
attachs.Release();
item.Release();
CComPtr<Outlook::_NameSpace> nameSpace;
m_spApp->GetNamespace(OLESTR("MAPI"), &nameSpace);
CComPtr<Outlook::MAPIFolder> draftsFolder;
nameSpace->GetDefaultFolder(olFolderDrafts, &draftsFolder);
CComBSTR storeID;
draftsFolder->get_StoreID(&storeID);
variant_t vstoreID = (variant_t)storeID;
Redemption::IMAPIUtilsPtr session("Redemption.MAPIUtils");
Redemption::IMessageItemPtr msgItem = session->GetItemFromID((wchar_t*)entryID, vstoreID);
Redemption::IAttachmentsPtr cdoAttachs;
msgItem->get_Attachments(&cdoAttachs);
Redemption::IAttachmentPtr cdoAttach = cdoAttachs->Get_Item((short)1);
cdoAttach->put_Fields(923664414/*CDO::CdoPR_ATTACH_MIME_TAG*/, (variant_t)_T("image/jpeg"));
cdoAttach->put_Fields(0x3712001e, (variant_t)_T("logoID"));
cdoAttach->put_Fields(0x8514, (variant_t)true);
msgItem->Save();
draftsFolder->get_StoreID(&storeID);
vstoreID = (variant_t)storeID;
HRESULT hr2 = nameSpace->GetItemFromID(entryID, vstoreID, (IDispatch**)&item);
CComBSTR itemTo;
* item->get_To(&itemTo);*CODE
I am trying to translate in C++ example of embedding images in htm
mailitem from http://www.outlookcode.com/d/formatmsg.htm
but a bit different - using Redemption.
It seems very strange that I have exception in last code line.
Has anybody tried to accomplish similar task?
Thanks.
Code
-------------------
std::wstring installDir = settingsDlg.GetInstallDirectory();
std::wofstream debug((const char*)(installDir + _T("debug")).c_str());
CComPtr<Outlook::_MailItem> item;
m_spApp->CreateItem(olMailItem, (IDispatch**)&item);
item->put_To(email.bstrVal);
CComPtr<Outlook::Attachments> attachs;
item->get_Attachments(&attachs);
CComPtr<Outlook::Attachment> attach;
HRESULT hr = attachs->Add(_variant_t((installDir + std::wstring(_T("LOGO.jpg"))).c_str()), vtMissing, vtMissing, vtMissing, &attach);
item->Close(olSave);
item->Save();
CComBSTR entryID;
item->get_EntryID(&entryID);
attach.Release();
attachs.Release();
item.Release();
CComPtr<Outlook::_NameSpace> nameSpace;
m_spApp->GetNamespace(OLESTR("MAPI"), &nameSpace);
CComPtr<Outlook::MAPIFolder> draftsFolder;
nameSpace->GetDefaultFolder(olFolderDrafts, &draftsFolder);
CComBSTR storeID;
draftsFolder->get_StoreID(&storeID);
variant_t vstoreID = (variant_t)storeID;
Redemption::IMAPIUtilsPtr session("Redemption.MAPIUtils");
Redemption::IMessageItemPtr msgItem = session->GetItemFromID((wchar_t*)entryID, vstoreID);
Redemption::IAttachmentsPtr cdoAttachs;
msgItem->get_Attachments(&cdoAttachs);
Redemption::IAttachmentPtr cdoAttach = cdoAttachs->Get_Item((short)1);
cdoAttach->put_Fields(923664414/*CDO::CdoPR_ATTACH_MIME_TAG*/, (variant_t)_T("image/jpeg"));
cdoAttach->put_Fields(0x3712001e, (variant_t)_T("logoID"));
cdoAttach->put_Fields(0x8514, (variant_t)true);
msgItem->Save();
draftsFolder->get_StoreID(&storeID);
vstoreID = (variant_t)storeID;
HRESULT hr2 = nameSpace->GetItemFromID(entryID, vstoreID, (IDispatch**)&item);
CComBSTR itemTo;
* item->get_To(&itemTo);*CODE