Mailkit: Get email From Message.From

Created on 6 Mar 2015  路  7Comments  路  Source: jstedfast/MailKit

Why these properties are't public?

Most helpful comment

I should explain my last comment better. An InternetAddressList is a list of InternetAddress items. An InternetAddress is an abstract class with 2 subclasses: GroupAddress and MailboxAddress.

A MailboxAddress is what you probably consider an "email address" that comes in the form "John Smith" <[email protected]>. The Name property on the MailboxAddress contains the string John Smith while the Address property contains the string [email protected].

A GroupAddress is something that is rarely used these days. It is a named list of addresses that might look something like this if you ever find an example of one in a message's To or Cc header: Friends: Joey <[email protected]>, Monica <[email protected]>, "Mrs. Chanandler Bong" <[email protected]>, Ross <[email protected]>, Rachel <[email protected]>;

Since you probably only care about the individual email addresses on the From header of the message, you could just use this:

foreach (var mailbox in message.From.Mailboxes)
    Console.WriteLine ("{0}'s email address is {1}", mailbox.Name, mailbox.Address);

Hope that helps.

All 7 comments

What do you mean it isn't public? Of course it's public...

        /// <summary>
        /// Gets the list of addresses in the From header.
        /// </summary>
        /// <remarks>
        /// <para>The "From" header specifies the author(s) of the message.</para>
        /// <para>If more than one <see cref="MailboxAddress"/> is added to the
        /// list of "From" addresses, the <see cref="Sender"/> should be set to the
        /// single <see cref="MailboxAddress"/> of the personal actually sending
        /// the message.</para>
        /// </remarks>
        /// <value>The list of addresses in the From header.</value>
        public InternetAddressList From {
            get { return addresses["From"]; }
        }

InternetAddress represent email? I dont find property to get native email. Sorry, if my question seemed not quite correct.

Correct, an InternetAddress is an email address with a Name property for the person's name and an Address property for the address (e.g. [email protected]).

I should explain my last comment better. An InternetAddressList is a list of InternetAddress items. An InternetAddress is an abstract class with 2 subclasses: GroupAddress and MailboxAddress.

A MailboxAddress is what you probably consider an "email address" that comes in the form "John Smith" <[email protected]>. The Name property on the MailboxAddress contains the string John Smith while the Address property contains the string [email protected].

A GroupAddress is something that is rarely used these days. It is a named list of addresses that might look something like this if you ever find an example of one in a message's To or Cc header: Friends: Joey <[email protected]>, Monica <[email protected]>, "Mrs. Chanandler Bong" <[email protected]>, Ross <[email protected]>, Rachel <[email protected]>;

Since you probably only care about the individual email addresses on the From header of the message, you could just use this:

foreach (var mailbox in message.From.Mailboxes)
    Console.WriteLine ("{0}'s email address is {1}", mailbox.Name, mailbox.Address);

Hope that helps.

jstedfast, thanks for help.

you're welcome

hey i think MailKit library is more difficult that Imap4Client library or is my idea

Was this page helpful?
0 / 5 - 0 ratings