'Is it possible to access redemption method of outlook add in using windows services

I have created outlook addin in C# to storing mail subjects in SQLite database using redemption(background). Can we access redemption method/Class of outlook add in into the windows service.

Outlook Object Model cannot be used from a service.



Solution 1:[1]

Do not use Outlook Object Model in a service. Secondly, you are assuming that you only have ContactItem objects in the folder, your code will break if there is a distribution list there.

The RDO family of Redemption objects can be used in a service

Solution 2:[2]

You are right, you shouldn't use the Outlook object model from a windows service. The Considerations for server-side Automation of Office article states the following:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Redemption is a wrapper around a low-level API (Extended MAPI). But add-ins is a feature of Office applications. Extended MAPI doesn't know wnything about them. So, any wrappers (Redemption in your case) around Extended MAPI don't provide access to add-ins.

Consider using any other communication methods with your add-in, for example - .NET Remoting (WCF). You may consider your managed add-in as a regular .Net application.

Solution 3:[3]

using Microsoft.Office.Interop.Outlook;
using OutLook = Microsoft.Office.Interop.Outlook;

and the code will be

 object missing = System.Reflection.Missing.Value;
        try
        {
            OutLook.MAPIFolder fldContacts = null;;
            OutLook._Application outlookObj = new OutLook.Application();
            string folderName = "Default";

            fldContacts = (OutLook.MAPIFolder)outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);

            //LOOPIN G THROUGH CONTACTS IN THAT FOLDER.
            foreach (Microsoft.Office.Interop.Outlook._ContactItem contactItem in fldContacts.Items)
            {

                    StringBuilder strb = new StringBuilder();
                    strb.AppendLine((contactItem.FirstName == null) ? string.Empty : contactItem.FirstName);
                    strb.AppendLine((contactItem.LastName == null) ? string.Empty : contactItem.LastName);
                    strb.AppendLine(contactItem.Email1Address);
                    strb.AppendLine(contactItem.Business2TelephoneNumber);
                    strb.AppendLine(contactItem.BusinessAddress);
                    //write to text file
                    StreamWriter sw = null;
                    sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\LogFile.txt", true);
                    sw.WriteLine(DateTime.Now.ToString() + ": " + strb.ToString());
                    sw.Flush();
                    sw.Close();

            }
        }
        catch (System.Exception ex)
        {
            throw new ApplicationException(ex.Message);
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Community
Solution 3 Vishva Nath Singh