Automate Microsoft Outlook from C++
- How to start
- Accessing the Outlook COM interfaces from C++ (Part 1)
- Accessing the Outlook COM interfaces from C++ (Part 2)
- The demo program
The demo program simply consist of a dialog box allowing you to fill in the information required to drive the class described in this article. The first thing you will notice by trying it is that unfortunately, it is not possible to completely automate the process as Outlook displays a security prompt asking the user to authorize the transmission of the e-mail.
Secondly, since the call to
Send() method is blocking, the UI becomes unresponsive until the user replies to the Outlook security prompt. I think that this problem also explains why the security prompt does not come itself to the foreground. In the original version of this tutorial, I was suggesting that creating a worker thread and doing the COM call from this thread could fix that problem. After some more COM reading, I have realized that this suggestion was not accurate. When initializing COM, unless it is specified otherwise with the function
CoInitializeEx(), COM will create a single threaded appartment (STA). One of the properties of a STA is that buried deep inside the COM libraries, there is suppose to be a message loop whose purpose is to exactly keep alive the UI associated with the appartment when a blocking COM call is performed. Why this message loop is not working with my program is beyong my knowledge. It might be because of some weird MFC/COM interaction that I am not aware of. If you know the answer, you are more than welcome to contact with me, I will update this tutorial and give you credit for the answer.
To conclude, the fact that the Outlook security model requires the end user to authorize an e-mail to be sent automatically greatly reduce the usefulness of automating Outlook. There exist a workaround to this problem that is to use the Extended MAPI and I will be investigating this option. If this is something that you would like to be notified when I come up with something, you can just let me know that you would like to be notified by sending me an e-mail with my small test program! For now, the procedure to automate Outlook is not limited to only Outlook. There is a lot of applications that you can automate to keep you busy until my next C++ Windows programming tutorial. Have fun!
In this section, you will find the books that I have consulted to build this C++ Windows programming article. Those books are great and filled with Windows/COM and Outlook programming gems that you should know. It is strongly recommended that you get yourself a copy of these books especially since from time to time, you can find these books at a bargain price. Take the time to check the prices. This is maybe your lucky day today!
- Original article.
- Fixed a remark about the demo program
Source: Thanks to Olivier Langlois http://www.olivierlanglois.net/Outlook_Automation_with_cpp_4.htmlNOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!