How to get "sent on behalf of" info from MapiMessage?

When I extract the “From” information from a MapiMessage, is the “sent of behalf of” string included? Or do I have to get this information separately? I need to be able to make sure that I capture this information. Will the following also get this information?

This is how I capture the “From” information:
output = msg.Headers.Get(“From”);
if (String.IsNullOrEmpty(output)) output = msg.SenderEmailAddress;

I do not have an example test message to use, so attached is a screenshot of what “sent of behalf of” looks like.

Hi,


Thank you for contacting support.

Please use the code snippet as given below to set the “On Behalf of” information for a MapiMessage instance.

C#
var message = new MapiMessage("From@domain.com", "to@gmail.com", “Subject”, “Body”);
message.Headers.Add(“on-behalf-of”, "onBehalfOf@domain.com");

Please note, in order to send such message, you need to set-up the "On Behalf Of" permissions to send email on behalf of the specified sending account.

Regards,

Thanks, Babar.

I am asking how to extract that information from a message that has it. Can you tell me how to extract that information? Also, do you have a test message I could use to try it?

Hi,


Sorry for the confusion.

I am afraid, I do not have such message. I am currently working on this with the development team, and hopefully soon I will share my finding with you.

Please accept my apologies for the trouble.
Regards,

Hi J,

We are sorry for a very delayed response. It seems we missed this query somehow.

I would like to share with you that you can extract this information from the message using the SentRepresentingEmailAddress property of MapiMessage. Please have a look at the following code sample for your reference and let us know if we can be of additional help to you.

MapiMessage mapiMsg = MapiMessage.FromFile("Sample Message with On Behalf Of.msg");

if (mapiMsg.Properties.Contains(MapiPropertyTag.PR_SENT_REPRESENTING_EMAIL_ADDRESS_W))
{
    Console.WriteLine("This email is sent from: {0} on behalf of {1}", mapiMsg.SenderEmailAddress, mapiMsg.SentRepresentingEmailAddress);
}