1
votes

I have just started developing an Addin for Outlook. When I run the Addin for the first time Outlook opens, the install window for the addin shows and it works without an issue. For example my test application moves any emails with the subject "USED CARS" into the recycle bin.

I changed the filter to "test", ran the debugger in VS2010 and sent my self an email with "test" in the subject. For some reason it did not work. However, it was still moving emails with the subject "USED CARS" even though I have changed the code.

I have already tried removing the Addin from within Outlook, this has not helped.

Below is the current code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace test3
{
public partial class ThisAddIn
{

    Outlook.NameSpace outlookNameSpace;
    Outlook.MAPIFolder inbox;
    Outlook.Items items;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        outlookNameSpace = this.Application.GetNamespace("MAPI");
        inbox = outlookNameSpace.GetDefaultFolder(
                Microsoft.Office.Interop.Outlook.
                OlDefaultFolders.olFolderInbox);

        items = inbox.Items;
        items.ItemAdd +=
            new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
    }

    void items_ItemAdd(object Item)
    {
        string filter = "test";
        Outlook.MailItem mail = (Outlook.MailItem)Item;
        if (Item != null)
        {
            if (mail.MessageClass == "IPM.Note" &&
                       mail.Subject.ToUpper().Contains(filter.ToUpper()))
            {
                mail.Move(outlookNameSpace.GetDefaultFolder(
                    Microsoft.Office.Interop.Outlook.
                    OlDefaultFolders.olFolderDeletedItems));
            }
        }

    }
    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
}
}

The original code can be found here.

Currently the only solution I have is to create a new project with a different name every time I make a change to the code.

Thank you for any help!

UPDATE

I have acquired a new PC as part of an upgrade at work and the most recent version of Visual studio and Outlook. This no longer an issue now.

1

1 Answers

0
votes

Your issue might be around the version of Visual studio. I have just tried this in VS2013 without any issues. Your code seems fine to me.