none
Event Firing in Outlook . RRS feed

  • Question

  • write  a office(outlook)  add in  C# to check whether an event is fired or not when a new email reaches outlook .

     

    Please help me out .

    Thursday, April 14, 2011 10:05 AM

Answers

  • Hell Nitesh_nytes,

     

    Thanks for posting in the MSDN Forum.

     

    I think Ken is right, we are highly recommend community members focus on one thread for one question. So that our community members can spend more time to research new issue.

     

    Ken is a most active MVP in the Outlook dev forum, he has helped many community members to resolve their issues since a long time ago. It will generate great labor for him if we post duplicate post in the forum.

     

    @Ken,

     

    Thanks for your active participation in the forum. We can see you have make a great deal of contributions in the forum, many community members get benefit from you hard work.

     

     

    Now back to this issue:

     

    According to your description, you want to check the Mail item when you receive it? Is it right?

     

    If it is, please take a look at the following code snippet, it will work. In this snippet I used a MessageBox to notify the user.

    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 System.Windows.Forms;
    
    namespace OutlookNewMail
    {
      public partial class ThisAddIn
      {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
          Outlook.Application olApp = Application;
          olApp.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(olApp_NewMailEx);
        }
    
        void olApp_NewMailEx(string EntryIDCollection)
        {
          Outlook.Application olApp = Application;
          Outlook.MailItem olMailItem = olApp.Session.GetItemFromID(EntryIDCollection);
          MessageBox.Show("You receive a mail as the subject is :\n" + olMailItem.Subject);
        }
    
        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
      }
    }
    
     

     

    I hope it can help you. If you has any problems, please feel free to let me know.

     

    Have a good day, both!

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 18, 2011 9:14 AM
    Moderator

All replies

  • Please explain what you want. You've already been pointed to code for NewMail() and NewMailEx() in a few threads you started. Did you bother look at any of those answers at all?
    Ken Slovak MVP - Outlook
    Thursday, April 14, 2011 2:46 PM
  • hey ken

     

    first of all be poilte .

    secondly , if i am not bothered then y should i post so much threads.

    till now i haven't find the appropriate sol. i m looking for.

    so i kindly request u to help me getting rid this problem instead of shouting.

    thanx

    nytes

     

     

     

    Friday, April 15, 2011 7:02 AM
  • Shouting is posting in all caps, and it's against forum policies to create duplicate posts as you're doing.

    But you're right, I won't respond to any of your posts in the future.


    Ken Slovak MVP - Outlook
    Friday, April 15, 2011 1:40 PM
  • Hell Nitesh_nytes,

     

    Thanks for posting in the MSDN Forum.

     

    I think Ken is right, we are highly recommend community members focus on one thread for one question. So that our community members can spend more time to research new issue.

     

    Ken is a most active MVP in the Outlook dev forum, he has helped many community members to resolve their issues since a long time ago. It will generate great labor for him if we post duplicate post in the forum.

     

    @Ken,

     

    Thanks for your active participation in the forum. We can see you have make a great deal of contributions in the forum, many community members get benefit from you hard work.

     

     

    Now back to this issue:

     

    According to your description, you want to check the Mail item when you receive it? Is it right?

     

    If it is, please take a look at the following code snippet, it will work. In this snippet I used a MessageBox to notify the user.

    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 System.Windows.Forms;
    
    namespace OutlookNewMail
    {
      public partial class ThisAddIn
      {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
          Outlook.Application olApp = Application;
          olApp.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(olApp_NewMailEx);
        }
    
        void olApp_NewMailEx(string EntryIDCollection)
        {
          Outlook.Application olApp = Application;
          Outlook.MailItem olMailItem = olApp.Session.GetItemFromID(EntryIDCollection);
          MessageBox.Show("You receive a mail as the subject is :\n" + olMailItem.Subject);
        }
    
        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
      }
    }
    
     

     

    I hope it can help you. If you has any problems, please feel free to let me know.

     

    Have a good day, both!

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 18, 2011 9:14 AM
    Moderator
  • Dear Ken,

    firstly , i m not shouting on u. u started it out first.

    secondly , i  was not unaware of your policies regarding duplicate posts .... so i am very sorry for the same.

    thirdly , I am a newly born Software Engineer. So u need to guide me to the right path. but instead of doing that u r making me ur enemy.

    i knw u have the capability , so please help me out , instead u r critising me at every stage.

    and moreover , what do u think if u r not gonna respond , then i shouldn't get a sol.

    Don't be in confusion MR. KEN that my problem will not be sorted out if u will stop responding , u r not the only MVP here .

    U r not at all the god of MICROSOFT Forums.

    So its better for us to stop this battle and  letz do some constructive work.

    i m very sorry for behaving like this , but u ve hurted my self respect .

    Take Care !!!

     

     

     

     

     

     

    Monday, April 18, 2011 9:22 AM
  • Thanx a lot Ken & Tom.

    now i can undstd.

     i m sry and highly grateful to u ppl.

     

     

     

     

    Wednesday, April 20, 2011 5:51 AM