Automate Microsoft Outlook from C++

(Last Updated On: October 19, 2010)
Learn the Secret

Get  our 2 Free Books

Get these now which land directly to their inbox.
Invalid email address

Automate Microsoft Outlook from C++

Contents

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.

Conclusion

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!

Bibliography

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!

History

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

Source: Thanks to Olivier Langlois http://www.olivierlanglois.net/Outlook_Automation_with_cpp_4.html

NOTE 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!
This entry was posted in Quant Development and tagged , , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs