Question

I am writing an Outlook Add-in that will be used to track number of emails replied to or forwarded. On the development PC, I have outlook 2010 and the code works fine but it's failing in outlook 2007 which is the version installed on end user's PC. Error message, "Cannot perform runtime binding to null reference". All I need before sending the email, is the mailbox sent from, the recipient's email address and the subject. here is my code for sending an email as a new email, can you please advise on what is the difference in the API used between office 2010 and 2007? what should I use instead?

    private void Send_Click(object sender, RibbonControlEventArgs e)
    {
        try
        {
            string _sub, _from, _to;
            var inspector = this.Context as Outlook.Inspector;
            dynamic mail = inspector.CurrentItem;
            _from = mail.SendUsingAccount.DisplayName.ToString();
            _to = mail.To.ToString();
            _sub = mail.Subject.ToString();
            /*
            some extra code to save to database before sending email
            */
            mail.Send();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error occured in send command");
        }
    } 
Was it helpful?

Solution

May I give you a simple advice; use Outlook 2007 template (of VS2010) instead. That works in both Outlook 2007 and 2010. If you have the luxury, add two projects to your solution, one for OL2007 and one for OL2010.

OTHER TIPS

As a general rule of thumb, you must develop on a machine with the lowest version of Outlook supported (Outlook 2007 in your case).

Or you can at least create on interop dll on a machine with Outlook 2007 installed, and add that interop dll (instead of adding Outlook COM object) as a reference in your project.

I came to realize that it wasn't a coding error, I used the suggestions above and used a computer with VS 2010 and Office 2007 and it fixed the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top