1

I'd like to get the SMTP header of the selected email in outlook.

I looked all over the API, but I can't find how to do this using the Office API : https://msdn.microsoft.com/en-us/library/office/fp142185.aspx

I also tried looking what's available in the Message object (https://msdn.microsoft.com/en-us/library/office/fp161175.aspx) :

Office.context.mailbox.item.?

I'm wondering if I should not use an Exchange Web Services (EWS) to do this ?

I'm asking because I have no idea if it is doable. I just tried to show you the process I've been through so far.

Elfayer
  • 4,411
  • 9
  • 46
  • 76

1 Answers1

3

Assuming that you have a reference to the MailItem object, do the following:

var headers = item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");

Where item is an instance of the MailItem class.

This will read the PR_TRANSPORT_MESSAGE_HEADERS property.

Yacoub Massad
  • 27,509
  • 2
  • 36
  • 62
  • So this is using C# in an EWS, right ? Using Microsoft.Office.Interop.Outlook library ? – Elfayer Sep 21 '15 at 14:17
  • This is in C# using the Microsoft.Office.Interop.Outlook library. Not EWS. I am assuming your are writing an outlook addin, why would you need EWS in an outlook addin? – Yacoub Massad Sep 21 '15 at 14:18
  • I don't know why I'd need an EWS, I never developed one. I'm trying to understand the context your talking about. I'm developing an add-in outlook, but I think there is a confusion on the internet about this key words "add-in Outlook", because I'm doing it using JS and HTML. It's the kind of add-in that you open inside Outlook via an ` – Elfayer Sep 21 '15 at 14:31
  • It seems we are doing different things. I really don't know about the kind of addins you are trying to make. I am not sure if there is a way in your case to read a MAPI property. – Yacoub Massad Sep 21 '15 at 17:44
  • That's why I thought I could write a C# program to do this using the API you are talking about and call it using an EWS... – Elfayer Sep 22 '15 at 06:12
  • If you use C# to write a [VSTO](https://en.m.wikipedia.org/wiki/Visual_Studio_Tools_for_Office) add-in, then you can use the code I provided which does not require you to use EWS. – Yacoub Massad Sep 22 '15 at 08:16