Wednesday 11 September 2013

Create a add-in in for outlook 2007 to append a message on create of activity

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;
using Microsoft.Office.Interop.Outlook;
using System.Windows;
using System.Windows.Forms;
namespace OutlookAddIn1
{
    public partial class ThisAddIn
    {
        Outlook.Inspectors inspectors;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            inspectors = this.Application.Inspectors;
            inspectors.NewInspector +=
            new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
            this.Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(saveEmail);

        }

        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
        public void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
            Outlook.TaskItem taskItem = Inspector.CurrentItem as Outlook.TaskItem;
           Outlook.AppointmentItem appItem = Inspector.CurrentItem as Outlook.AppointmentItem;
            DialogResult res = MessageBox.Show("Do you want to create Private Activity ? Press ok  ", "", MessageBoxButtons.OKCancel);


            if (mailItem != null && (res == DialogResult.OK))
            {
                if (mailItem.EntryID == null)
                {
                    mailItem.Subject = "[MNPI ACTIVITY:]";
            

                }

            }
            if (taskItem != null)
            {
                if (taskItem.EntryID == null)
                {

                    taskItem.Subject = "Private Task";

                }

            }
            if (appItem != null)
            {
                if (appItem.EntryID == null)
                {

                    appItem.Subject = "Private Appoinment";

                }

            }


        }

        private void saveEmail(object Item, ref bool Cancel)
        {

        }

    }

}

No comments:

Post a Comment