How to access Outlook e-mail with C++
There is an example in Qt docs of how to access Outlook e-mail with C++ and MSOUTL, but for me the described scenario didn’t work as expected and I needed to modify some steps. Here is what I’ve done to make it work. I used Windows 7 and Outlook 14.
Create MSOUTL
Instead of creating MSOUTL sources from .pro file, I’ve created it manually and copy-pasted the resulting files into the repository. It was necessary because later I had to modify these files. So, I skipped the TYPELIBS line in .pro, and I’ve done it manually from cmd (adjust your paths to Qt and Microsoft Office):
Files MSOUTL.h and MSOUTL.cpp are created. I included them to project like normal source files.
Fix “Use of enum ‘MsoFeatureInstall’ without previous declaration…”
With these files included, I’ve tried to compile basic application of Outlook::Application. It gave me errors like:
use of enum ‘MsoFeatureInstall’ without previous declaration enum MsoFeatureInstall;
I’ve learned that this is an already reported bug. I’ve applied suggested fix to MSOUTL.h:
It helped and my code compiled.
Proper usage
After successful setup reading e-mails is easy. Following code reads subjects and bodies of e-mails from Inbox:
The minimal app for reading e-mails is on my Github/MailReader. I didn’t include MSOUTL files there as I’m not sure about their licence and in fact the library can be different for various Outlook versions.
Troubleshooting
If you try to implement very simple usage of MSOUTL and you have errors like:
QAxBase::setControl: requested control {0006f03a-0000-0000-c000-000000000046} could not be instantiated
then use solution suggested in this topic. I’ve had this problem when I tried to create Outlook::Application object directly in main() function. When I moved it to class and wrapped it with a Widget, the problem disappeared.