Outlook 2007 automation

I'm working on an application that need to automatically generate emails with the following critera:

1. Sent emails need to include the users standard signature
2. The application needs to work in an environment with different versions of office (XP, 2003 and 2007) and windows (XP, Vita and Win 7)

I am attempting to automate outlook using late binding and reflection to achieve this (Perhaps there is a better way?) and I've run into a problem on a windows 7 machine running Office XP and Outlook 2007:


returns null

This same code runs ok on a winXP machine running Office XP and Outlook 2003. Word and excel automation works fine on the Win7 machine using this method.

Has something changed in outlook 2007 that would stop this working? I've spent half a day on it now and could really do with any pointers!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A huge problem i have run into as far as automating Outlook is that it ask for permission to access the address book as well as send the email. I, however, was using the Microsoft.Office.Interop.Outlook.

Here's what i did:

Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailMessage = outlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mailMessage.Subject = "Subject";
mailMessage.Body = bodyTextBox.Text;
mailMessage.Importance = Outlook.OlImportance.olImportanceHigh;
mailMessage.Recipients.Add("Recipient Name");

Open in new window

Since that wasn't automated enough for me, i ended up going with an approach that will avoid outlook all together:
private static bool SendMail(string[] to, string from, string subject, string body)
      	MailMessage msg = new MailMessage();
            for (int i = 0; i < to.Length; i++)

            msg.From = new MailAddress(from);
            msg.Subject = subject;
            msg.Body = body;
            msg.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient("smtp.example.com");
            client.Credentials = new NetworkCredential(userName, password);
            return true;
      catch (Exception exc)
      	Console.WriteLine(exc.Message, System.DateTime.Now + " - Unable to Send Email");
		return false;

Open in new window

phillarbyAuthor Commented:
Thanks for the reply.

I eventually downgraded from outlook 2007 to 2003 and creating an outlook app through automation now works fine, but outlook isn't entirely stable on my machine. I don't think it likes downgrading! This isn't a long term solution though as we will be getting more outlook 2007/2010 users in the future.

There is a new security model in outlook 2007 that uses trusts to get around the need to prompt for permissions by using trusts - in fact, this may be the root of my problem. I have also used a library called outlook redemption in the past that gets around this for earlier versions.

I'd love to be abe to avoid outlook all together, but sadly it is quite integrated into our workflow at the moment. Going down another route would add all kind of operational complications that I'd rather not get into at the moment!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.