

How do I create a button in an Outlook window for mail from an inbox (double-cli...
source link: https://www.codesd.com/item/how-do-i-create-a-button-in-an-outlook-window-for-mail-from-an-inbox-double-click-on-mail.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How do I create a button in an Outlook window for mail from an inbox (double-click on mail)?
I am programmer rookie, and I have to create outlook 2007 add-in. I should create a button on the ribbon or taskbar but on the window for the single mail from the inbox. You know, when you double click on mail in inbox, the new window appears. And in that window I need a button which opens a new form with some treeview. Main problem for me is how to create that button. This is all new for me so I'll be very thankful for the help.
OK, I've done some research and this code below kinda works :) But I'll be very grateful if someone experienced could see this and tells me is it OK and what and how I could change it. This is just beginning of the bigger project.
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 OutlookAddInMishko
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Inspectors = this.Application.Inspectors;
Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
private Office.CommandBarButton buttonOne;
private Outlook.Inspectors Inspectors;
public static Microsoft.Office.Interop.Outlook.Inspector InsMail;
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
if (Inspector.CurrentItem is Outlook.MailItem)
{
tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
bool exists = false;
foreach (Office.CommandBar cmd in Inspector.CommandBars)
{
if (cmd.Name == "EAD")
{
//exists = true;
cmd.Delete();
}
}
Office.CommandBar newMenuBar = Inspector.CommandBars.Add("EAD", Office.MsoBarPosition.msoBarTop, false, true);
buttonOne = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true);
if (!exists)
{
buttonOne.Caption = "Scan this mail";
buttonOne.Style = Office.MsoButtonStyle.msoButtonCaption;
buttonOne.FaceId = 1983;
//Register send event handler
buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click);
newMenuBar.Visible = true;
}
}
}
private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
{
ProcessMessages();
}
private Form1 form1 = null;
private void ProcessMessages()
{
if (form1 == null)
{
form1 = new Form1(this.Application);
}
form1.ShowDialog();
}
}
}
namespace OutlookAddInMishko
{
public partial class Form1 : Form
{
protected Outlook.Application App;
public Form1()
{
InitializeComponent();
}
public Form1(Outlook.Application _app)
{
App = _app;
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
label1.Text = "Total number of mails in inbox: " + App.ActiveExplorer().CurrentFolder.Items.Count.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
Outlook.MailItem item = (Outlook.MailItem)App.ActiveInspector().CurrentItem;
textBox1.Text += "From: " + item.SenderName + "\r\n\n";
textBox1.Text += "Subject: " + item.Subject + "\r\n\n";
textBox1.Text += "Body: \r\n\n" + item.Body + "\r\n";
textBox1.Text += "Mail contains: " + item.Attachments.Count + " attachment(s).\r\n\n";
}
}
}
Recommend
-
22
window.location.origin and Yahoo! Mailwindow.location.origin and Yahoo! Mail 14 Apr 2014 Here’s a pop quiz to keep you on your toes. What’s the rel...
-
13
Sending mail without having to see your inbox For the longest time, the way I handled e-mail was with the "mail" program which came with the system. It was simple, fast (it never did "hourglass" or "beachball" garbage on me), and...
-
6
Creating Outlook e-mail with multiple recipients and attachments advertisements I have a web application, written in PHP, w...
-
7
Netflix has added a 'Double Thumbs Up' button and it does exactly what viewers expect Netflix has added a “Double Thumbs Up” button for TV shows, movies, and other content that the company offers for streaming. The new indicator is an...
-
6
Tech at WorkYour work inbox is a mess. These tips could help manage your emailsManaging...
-
13
If your Microsoft Outlook inbox had lots of spam today, you were not alone [Update]...
-
12
Microsoft adds Excel and PowerPoint's Accessibility ribbon to Outlook for Windows...
-
5
The new Outlook for Windows will start to replace the Mail and Calendar apps in Sept. 2024...
-
7
Microsoft now says the new Outlook will replace Mail and Calendar apps by the end of 2024...
-
2
Outlook/Hotmail is no longer blocking my mail server 涛叔 2023-12-23 ⏳1.9 min(0.8k words) After some struggle, I managed to de-list the address of my ma...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK