using C# to automate Outlook

D

David R

I need to create an email message from my Windows application, address it and
populate it with a given body of text. I am using VS2005 and C#. If found
an example that should work, namely the "How to automate Outlook and Word by
using Visual C# .NET to create a pre-populated e-mail message that can be
edited" which can be found here

http://support.microsoft.com/?kbid=819398

Problem is, the code fails at the same place, and I have tried creating the
project twice:

Outlook.MailItemClass mItem = (Outlook.MailItemClass)doc.MailEnvelope.Item;

Error:
Unable to cast COM object of type 'System.__ComObject' to class type
'Microsoft.Office.Interop.Outlook.MailItemClass'. COM components that enter
the CLR and do not support IProvideClassInfo or that do not have any interop
assembly registered will be wrapped in the __ComObject type. Instances of
this type cannot be cast to any other class; however they can be cast to
interfaces as long as the underlying COM component supports QueryInterface
calls for the IID of the interface.

I suspect that there is something wrong with the wrappers, but do not know
where to look, or how to fix it. Any ideas?

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top