I am developing an Outlook plugin using add-in-express. There are two mail account (A) which has granted calendar access to account (B) through delegation. I am developing the plugin for account (B).
Here is what I want to implement.
I open the calendar account of (A) after login to outlook using the credentials of account (B) (as a user, not by C# code). Then double click on some date of the calendar, which leads to open a new inspector window for me. In the ribbon of the inspector, there is a button coming from my pluging. After user click the button, I need to show the email owner’s (account (A)) email and name in the body of the inspector.
Here is the code for the button
private void adxRibBtnDelegateTest_OnClick(object sender, IRibbonControl control, bool pressed)
{
Outlook.Inspector currentInspector = null;
Outlook.AppointmentItem myAppointment = null;
Outlook.MailItem myMailItem = null;
string ownerEmail = string.Empty;
string ownerName = string.Empty;
try
{
currentInspector = Globals.ObjOutlook.ActiveInspector();
myAppointment = currentInspector.CurrentItem as Outlook.AppointmentItem;
myMailItem = currentInspector.CurrentItem as Outlook.MailItem;
Outlook.AppointmentItem appt = currentInspector.CurrentItem as Outlook.AppointmentItem ;
Outlook.MAPIFolder parent = appt.Parent as Outlook.MAPIFolder;
// ToDo:
// Here I need to develop the functionality for getting the delegated account owner's email and name
string body = "\n\nOwner's Email\t: " + ownerEmail
+ "\nOwner's Name\t: " + ownerName;
if (myAppointment != null)
{
myAppointment.Body = body;
}
else if (myMailItem != null)
{
myMailItem.Body = body;
}
}
catch (Exception ex)
{
Debug.DebugMessage(2, "Error in AddNewNationalCall() : " + ex.Message);
}
finally
{
if (myAppointment != null) Marshal.ReleaseComObject(myAppointment);
if (myMailItem != null) Marshal.ReleaseComObject(myMailItem);
if (currentInspector != null) Marshal.ReleaseComObject(currentInspector);
GC.Collect();
}
}
Can you please advise me on this? Thank you.
The Outlook object model doesn't provide anything for that. You may try to get the Store object and check its name (see the Store property of the Folder class). Typically the display name contains an email address (see DisplayName), but it is not a panacea.
I'd recommend using any low-level property viewer tool such as MFCMAPI or OutlookSpy. They allow observing low-level property values (as well as OOM) you may access using the PropertyAccessor class. Outlook is just a big wrapper around Extended MAPI.