How can I get a reference to the selected e-mail in Outlook?

Add-in Express™ Support Service
That's what is more important than anything else

How can I get a reference to the selected e-mail in Outlook?
Selected e-mail reference in Outlook 
Oliver Degnan




Posts: 54
Joined: 2005-02-03
I am writing an add-in for Outlook with one CommandBar and one button on it.

After clicking the button, I want to get all information pertaining to the selected e-mail. If no e-mail is selected, nothing should happen.

I need to get a reference to the selected e-mail to get access to all parts of the e-mail such as FROM, TO, SUBJECT, BODY, HEADER.

Any help is deeply appreciated.

Thank you.

Oliver
Posted 15 Feb, 2005 14:38:01 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Oliver. Try the following code:
Outlook._MailItem mailObj;
Outlook._Explorer explorer = OutlookHost().ActiveExplorer();
Outlook.Selection selObject = explorer.Selection;
object item = selObject.Item(1);
if (item is Outlook._MailItem)
{
mailObj = item as Outlook._MailItem;
string to = mailObj.To;
string subject = mailObj.Subject;
string body = mailObj.Body;
string from = mailObj.SenderName;
}
How to get the header of mail you can see in our ADX Toys. Just download it from here: http://www.add-in-express.com/free-addins/
Posted 16 Feb, 2005 06:08:47 Top
Oliver Degnan




Posts: 54
Joined: 2005-02-03
Super. It works!

Thank you very much!

I love your ExpressAdd-in.NET!!

Oliver
Posted 16 Feb, 2005 09:13:36 Top