My blog
My LinkedIn Profile

BOOKS i'm reading

Napoleon Hill Keys to Success: The 17 Principles of Personal Achievement, Napoleon Hill, ISBN: 978-0452272811
The 4-Hour Workweek: Escape 9-5, Live Anywhere, and Join the New Rich (Expanded and Updated), Timothy Ferriss, ISBN: 978-0307465351
The Fountainhead, Ayn Rand, ISBN: 0452273331

Automate Microsoft Outlook from C++

Olivier Langlois, IT superstar coach, Dominate LinkedIn Formula author
by Olivier Langlois


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.

Microsoft Office Outlook security prompt

Secondly, since the call to MailItem 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!


  • 09-25-2006:
    • Original article.
  • 11-03-2006:
    • Fixed a remark about the demo program

Page 1 2 3 4

Back to the tutorials list

Home :: Fractals :: Tutorials :: Books :: My blog :: My LinkedIn Profile :: Contact