Don Don - 2 months ago 18
C# Question

How to select the EmailBody for current opened outlook window

I made code for selecting the email body. However, this code only select the email body for I selected in the email list bar. I wonder know how I can make it change to make it to select the current opened email rather than I selected. When I selected a email, and double click, the ribbon will come out. It is possible that I remain the email window on, and select other email, but not double click it. Then, I click my function button, it will show up the email body that I selected in the email list bar, not the email that i open.

Here is code:

private void uploadEmail_Click(object sender, RibbonControlEventArgs e)
{

Outlook.Application currentmail = new Outlook.Application();
if (currentmail.ActiveExplorer().Selection.Count > 0)
{
Object selObject = currentmail.ActiveExplorer().Selection[1];

if (selObject is Outlook.MailItem)
{
Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
String htmlBody = mailItem.HTMLBody;
String Body = mailItem.Body;

using (ViewingMailBody viewingMailBody = new ViewingMailBody(Body))
{
viewingMailBody.ShowDialog();
}
}
}
}

Answer

Use Application.ActiveInspector.CurrentItem.

Comments