You have to get the IsSeen
and UniqueId
properties from the ImapMessageInfo
object. However, MailMessage
object does not know anything about a protocol specific object (e.g. ImapMessageInfo
).
I'd recommended you to retrieve or search your messages first as ImapMessageInfo
s and then create a MailMessage
object for each of them.
// get a sample collection of message infos
ImapMessageCollection messageInfos =
client.Search(ImapSearchParameter.Arrived(new DateTime(2011, 6, 2)));
// process each message
foreach (ImapMessageInfo messageInfo in messageInfos)
{
// get MailMessage for a MessageInfo
MailMessage message = client.GetMailMessage(messageInfo.SequenceNumber);
//alternative retrieval if you cannot rely on SequenceNumber (*)
//MailMessage message = client.GetMailMessage(messageInfo.UniqueId);
// use both properties of MessageInfo and MailMessage
Console.WriteLine("-------------------------------------");
Console.WriteLine("SUBJ.:\t{0}", messageInfo.Subject);
Console.WriteLine("READ:\t{0}", messageInfo.IsSeen); // MessageInfo specific property
Console.WriteLine("BODY:\r\n{0}", message.BodyText); // MailMessage specific property
}
*Retrieving MessageInfo by SequenceNumber can be faster than getting by UniqueId, but you cannot use SequenceNumber if you are deleting messages in the same session.
If you cannot use the procedure described above, you can try to find a ImapMessageInfo
for each MailMessage
object using search for an MessageId
field:
MailMessage message;
// ...
ImapMessageCollection messageInfos =
client.Search(ImapSearchParameter.Header("Message-Id", message.MessageId.Id));
ImapMessageInfo messageInfo = messageInfos[0];
Be aware that searching by MessageId will be probably more time-consuming than retrieving messages by UniqueId or SequenceNumber.