c++ - How to add attachments to outlook using MFC -
i trying open outlook mfc code send mail attachments. not able add attachments don't know method use , when mail sent, outlook not opening , mail sent directly.
i have used following code:
void coutlookdlgdlg::onbnclickedopenoutlook() { capplication olapp; coleexception e; if (!olapp.createdispatch(_t("outlook.application"), &e)) { cstring strerr; strerr.format(_t("createdispatch() failed w/error 0x%08lx"), e.m_sc); afxmessagebox(strerr, mb_setforeground); return; } cnamespace olns(olapp.getnamespace(_t("mapi"))); colevariant covoptional((long)disp_e_paramnotfound, vt_error); olns.logon(covoptional, covoptional, covoptional, covoptional); cmailitem olmailitem(olapp.createitem(olmailitem)); olmailitem.put_to(_t("xyz@abc.com")); olmailitem.put_subject(_t("xyz...")); olmailitem.put_body(_t("hi mnc,\n\n") _t("\tmail testing!\n\n")); olmailitem.send(); olns.logoff(); }
the outlook object model common kind of applications , programming languages.
the add method of attachments class creates new attachment in attachments collection (see attachments property of mailitem class).
if need display mail item before sending may use display method of mailitem class.
finally, may find following articles helpful:
Comments
Post a Comment