BodyParts are null

Oct 14, 2008 at 9:35 PM
Hi all,

Can someone help me figure out how to retrieve the message content.  I have the following code, but the BodyParts appear to be null.
--------------------------------------------------------------------

connection.Open();
authenticate.Login();

ImapMailbox mailbox = command.Select(@"INBOX");
mailbox = command.Fetch(mailbox);
foreach (ImapMailboxMessage message in mailbox.Messages)
{
  // filter by date
  if (message.Sent.CompareTo(startdate) >= 0 && message.Sent.CompareTo(enddate) <= 0)
  {
  
 Console.Write("<entry etag=\"" + message.UID + "\">");
    Console.Write(" <id>" + message.MessageID + "</id>");
    Console.Write(" <published>" + message.Sent.ToString(@"yyyy\-MM\-dd\THH\:mm\:ss\.\0\0\0zzz") + "</published>"); // Could use message.TimeZone to make this date more accurate
    Console.Write(" <updated>" + message.Received.ToString(@"yyyy\-MM\-dd\THH\:mm\:ss\.\0\0\0zzz") + "</updated>");
    Console.Write(" <title>" + HttpUtility.HtmlEncode(message.Subject) + "</title>");
    Console.Write(" <content type=\"html\">");

    foreach(ImapMessageBodyPart bodypart in message.BodyParts)
    {
       Console.Write("<pre>" + HttpUtility.HtmlEncode(bodypart.BodyPart) + " " +HttpUtility.HtmlEncode(bodypart.Data) + "</pre>");
    }

    Console.Write(" </content>");
    Console.Write(" <link rel=\"alternate\" type=\"text/html\" href=\"" + HttpUtility.HtmlEncode(@"http://mail.bi-tech.com") + "\" title=\"" + HttpUtility.HtmlEncode(message.Subject) + "\"/>");
    Console.Write("</entry>");
    }
}
authenticate.Logout();
connection.Close();

-------------------------------------------------------
The problem is that message.BodyParts is null, but I know these messages have body parts. 

Can anyone show me how to fetch the actual message?

Thanks,
Trev