andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

How to get PlainText or Html Text ? #82

Open LeMoussel opened 12 years ago

LeMoussel commented 12 years ago

I'm trying to get Plain Text or HTML Text of email but I cannot find any documentation and I did not find features such as EmailMessage.BodyText.Text / EmailMessage.BodyHtml.Text or EmailMessage.GetBodyPlainText() / EmailMessage.GetBodyHTMLText()

I developed this C# code to do. What do you think?

   IList<Attachment> iList;
   string HtmlText = "", PlainText = "";

   for (var i = pop3.GetMessageCount() - 1; i >= 0; i--)
   {
      MailMessage msg = pop3.GetMessage(i);
      TextBody = msg.Body;
      iList = msg.AlternateViews as IList<Attachment>;
      if (iList.Count == 0) iList = msg.Attachments as IList<Attachment>;
      if (iList.Count > 0)
      {
           TextBody = iList[0].Body;
           HtmlBody = iList[1].Body;
      }
   }
MichalPaszkiewicz commented 10 years ago

Thank you SO MUCH. You are awesome!