+1 vote

I have the following code:

var eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder().CreateFromEml(eml);

The method CreateFromEml successfully creates the IMail object but the "From" property contains a null value for address.

The value I am getting is:

"Name='Microsoft Exchange Server 2010' Address=''"

Name is populated, address is not. Why is the address not populated?

by (250 points)

1 Answer

0 votes

MailBuilder.CreateFromEml parses eml (MIME) data retrieved from the server.

IMail.From represents parsed From: header. I suspect there is no email address there.

Please take a look at the eml (MIME) data and the value of From: header line:

string emlAsString = System.Text.Encoding.ASCII.GetString(eml);

Alternatively you may turn on logging
and observe eml (MIME) data returned by the server:

https://www.limilabs.com/blog/logging-in-mail-dll

by (301k points)
The address value is empty in the MIME data.  How can an email not have an address for a sender?  It was a message that was send "on behalf of" someone else.
It is a sending client that creates a message, it can create a broken message if it wants. Also Exchange server is known to modify messages in peculiar ways - so it may be a reason.

Using Mail.dll you can access any MIME header, examine the message carefully. You can check IMail.Sender ("Sender: " header) as well.
...