I am creating a addin for Office 2007 using C#. This addin is responsible to display email header information in a new pane whenever a user clicks on email from email list within Inbox pane. Now I am not sure how do I get mouse click event on the Inbox pane when a user selected an email and read that emails header information. Any helpful pointer?
Asked
Active
Viewed 1,299 times
5
-
6Have a look here, maybe it helps: http://www.eggheadcafe.com/software/aspnet/34867978/event-for-email-message-select.aspx. You shouldn't care about the mouse click, but about a selection change in the list of emails. – Daniel Hilgarth Mar 14 '11 at 12:04
-
Thanks Daniel, link you provided was helpful. – UJ. Mar 16 '11 at 05:03
-
1Should this be marked as answered then? – Rob Feb 22 '12 at 13:47
-
1@DanielHilgarth would have to create an answer out of his comment so that it could be marked as the answer – Jason Kleban Apr 13 '12 at 14:56
2 Answers
0
You can use the Microsoft V11.0 outlook object library (add the reference) and then query a MAPI mailbox:
http://geekswithblogs.net/TimH/archive/2006/05/26/79720.aspx or http://support.microsoft.com/kb/310258
Some requirements for accessing exchange inboxes with MAPI or POP3: C# MAPI to read exchange server inbox
Now, to get which inbox message has been selected, you could use:
Outlook.Explorer explorer = null;
explorer = outlookObj.ActiveExplorer();
if (explorer.Selection.Count > 0)
{
var sel = explorer.Selection[1];
if (sel is Microsoft.Office.Interop.Outlook.MailItem)
{
var item = sel as MSOutlook.MailItem;
MessageBox.Show("Selected letter: "+item.Body);
}
}

Community
- 1
- 1

negEntropy
- 319
- 1
- 5
-
This code looks promising, but what event should it be attached to in order to get the actual selected item? – IamSierraCharlie Aug 11 '19 at 04:11
0
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
try
{
Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
if (tmpMailItem != null)
{
if (Inspector.CurrentItem is Outlook.MailItem)
{
tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
string to= tmpMailItem.To;
string body = tmpMailItem.Body;
}
}
}
catch
{
}
}

Sharique Ansari
- 1,458
- 1
- 12
- 22