Few days back , questioned was thrown at me like - hey dude , have you ever tried extending ribbon in outlook? and my answer at that point was 'No'. then next question was - is it possible to have some buttons in the ribbon which will allow you to create new meeting request and mails with predefined data and recipients?
Question did sound interesting to me , and that immediately taken me in front of machine. I opened up VS 2010 to see what can be done.
It is easy to extend ribbon of Office applications using VS 2010 , as it gives you the project template.
I will not cover up how to create new ribbon and add buttons on it but here is what I learned on that evening - how to create new meeting request and new mails with predefined contents.
Just added two buttons on my custom ribbon , and added code behind of custom ribbon and buttons
Question did sound interesting to me , and that immediately taken me in front of machine. I opened up VS 2010 to see what can be done.
It is easy to extend ribbon of Office applications using VS 2010 , as it gives you the project template.
I will not cover up how to create new ribbon and add buttons on it but here is what I learned on that evening - how to create new meeting request and new mails with predefined contents.
Just added two buttons on my custom ribbon , and added code behind of custom ribbon and buttons
private Application
m_outlookApp;
private Explorer
m_outlookActiveWindow;
- To create new mail programmatically
try
{
m_outlookApp = Globals.ThisAddIn.Application;
m_outlookActiveWindow
= m_outlookApp.ActiveExplorer();
MailItem mailItem = m_outlookApp.CreateItem(OlItemType.olMailItem) as
MailItem;
if (mailItem != null)
{
mailItem.Body
= "Add Your Contents Here..";
mailItem.Subject
= "Add Appointment Subject Here..";
mailItem.To
= "target.user@smtp.com";
mailItem.Save();
mailItem.Display(true);
Marshal.ReleaseComObject(mailItem);
}
}
catch (System.Exception
ex)
{
System.Windows.Forms.MessageBox.Show("Error:
" + ex.Message);
}
- To create new meeting request programmatically
try
{
m_outlookApp
= Globals.ThisAddIn.Application;
m_outlookActiveWindow
= m_outlookApp.ActiveExplorer();
AppointmentItem appItem = m_outlookApp.CreateItem(OlItemType.olAppointmentItem) as AppointmentItem;
if (appItem != null)
{
appItem.Body
= "Add Your Contents Here..";
appItem.Subject
= "Add Appointment Subject Here..";
appItem.RequiredAttendees
= "target.user1@smtp.com;target.user2@smtp.com";
appItem.OptionalAttendees
= "optional.user1@smtp.com";
appItem.Start
= DateTime.Now.AddHours(1);
appItem.End
= DateTime.Now.AddHours(2);
appItem.Save();
appItem.Display(true);
Marshal.ReleaseComObject(appItem);
}
}
catch (System.Exception
ex)
{
System.Windows.Forms.MessageBox.Show("Error:
" + ex.Message);
}
References:
http://blogs.msdn.com/b/mcsuksoldev/archive/2010/10/01/building-and-deploying-an-outlook-2010-add-in-part-1-of-2.aspx
http://www.add-in-express.com/creating-addins-blog/2011/11/04/outlook-create-appointment-item/
http://msdn.microsoft.com/en-us/library/bb612741.aspx