locked
Outlook VSTO Question RRS feed

  • Question

  • Hello All,

    I have a question on outlook vsto programming.

    My users are using both outlook 2003 and 2007 (some of them will start using 2010 shortly).

    The users need a mailbox cleanup utility. Which will

    1. Group all the emails by user ids. The order can be either by DESC total size or DESC total number of emails.
    2. Utility should then allow the delete of emails.

    The utility should work on all the mail files attached to the outlook profile (psts and Osts).

    So my question is

    1. Can this be done
    2. Will I have to write 3 programs (one for 2003, 2007 and 2010) or can this be achieved in one program.
    Monday, March 8, 2010 5:51 PM

Answers

  • Hello,

    For the first question, we could iterate all mails in every folder of Outlook by foreach block. The code like this,

               foreach(Outlook.Folder folder in Globals.ThisAddIn.Application.Session.Folders)
                    foreach (Outlook.MailItem mi in folder.Items)
                    {
                        if (mi != null)
                        {
                           
                        }
                    }

    By using code above, it will access all mail items included in ost and pst files. Then we could use Delete method to delete this mail item [See: MailItem.Delete Method]. To group all mails by using email address, unfortunately, there is no a direct way by using Outlook Object Model. However, by iterating all mail items, we could use the properties of a MailItem object to group it, such Size and Recipients property [See: MailItem Object Members]. It will be a very complicated task for you. Here, we could make statistics for all mail items.

    For the second question, it is not recommended to create one solution for multiple versions of Office. As this KB 840585 said, "The Office 2003 managed code add-ins must be built against the Office 2003 PIAs. The Office 2007 managed code add-ins must be built against the Office 2007 PIAs. Therefore, if you build an add-in solution that you intend to use with several versions of Office, Microsoft recommends that you build a version of your add-in for each version of Office that you intend to support."  

    Also here is a blog introduces that we could build one add-in for multiple versions of Office: http://blogs.msdn.com/andreww/archive/2007/06/15/can-you-build-one-add-in-for-multiple-versions-of-office.aspx.
    For this, it statements as below, You need to target the lowest common denominator (Outlook 2003), and then write conditional code to use version-specific functionality dependent on which version you're running in.

    For this topic, please refer to these threads:

    Building Outlook addins (compatibility office 2003 and 2007; Primary Interop Assemblies (PIA) are missing): http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/6b36a867-0f65-492c-a213-907acdf6b19e/.

    VSTO Excel 2003 and 2007: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/ea8cfa83-4537-40fd-ac2a-a9045d3e2127/.

    If you have any concern for this, please feel free to follow up.

    Best regards,
    Bessie



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by MSDN Student Wednesday, March 10, 2010 8:10 AM
    Wednesday, March 10, 2010 6:00 AM

All replies

  • Bump! Can you please help!
    Tuesday, March 9, 2010 6:30 PM
  • Hello,

    For the first question, we could iterate all mails in every folder of Outlook by foreach block. The code like this,

               foreach(Outlook.Folder folder in Globals.ThisAddIn.Application.Session.Folders)
                    foreach (Outlook.MailItem mi in folder.Items)
                    {
                        if (mi != null)
                        {
                           
                        }
                    }

    By using code above, it will access all mail items included in ost and pst files. Then we could use Delete method to delete this mail item [See: MailItem.Delete Method]. To group all mails by using email address, unfortunately, there is no a direct way by using Outlook Object Model. However, by iterating all mail items, we could use the properties of a MailItem object to group it, such Size and Recipients property [See: MailItem Object Members]. It will be a very complicated task for you. Here, we could make statistics for all mail items.

    For the second question, it is not recommended to create one solution for multiple versions of Office. As this KB 840585 said, "The Office 2003 managed code add-ins must be built against the Office 2003 PIAs. The Office 2007 managed code add-ins must be built against the Office 2007 PIAs. Therefore, if you build an add-in solution that you intend to use with several versions of Office, Microsoft recommends that you build a version of your add-in for each version of Office that you intend to support."  

    Also here is a blog introduces that we could build one add-in for multiple versions of Office: http://blogs.msdn.com/andreww/archive/2007/06/15/can-you-build-one-add-in-for-multiple-versions-of-office.aspx.
    For this, it statements as below, You need to target the lowest common denominator (Outlook 2003), and then write conditional code to use version-specific functionality dependent on which version you're running in.

    For this topic, please refer to these threads:

    Building Outlook addins (compatibility office 2003 and 2007; Primary Interop Assemblies (PIA) are missing): http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/6b36a867-0f65-492c-a213-907acdf6b19e/.

    VSTO Excel 2003 and 2007: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/ea8cfa83-4537-40fd-ac2a-a9045d3e2127/.

    If you have any concern for this, please feel free to follow up.

    Best regards,
    Bessie



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by MSDN Student Wednesday, March 10, 2010 8:10 AM
    Wednesday, March 10, 2010 6:00 AM