如何使用AE.Net.Mail获取PlainText或Html文本? [英] How to get PlainText or Html Text using AE.Net.Mail?

查看:184
本文介绍了如何使用AE.Net.Mail获取PlainText或Html文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AE.Net.Mail获取电子邮件的纯文本或HTML文本。
我找不到任何文件。

I'm trying to get Plain Text or HTML Text of email using AE.Net.Mail. I cannot find any documentation.

using (Pop3Client pop3 = new AE.Net.Mail.Pop3Client("pop3Server", "login", "pwd", 995, true))
{
   for (var i = pop3.GetMessageCount() - 1; i >= 0; i--)
   {
      MailMessage Msg = pop3.GetMessage(i);
      string HtmlText = Msg.??????
      string PlainText = Msg.??????                
   }
}

编辑:我发现这个解决方案

Edit : I found this solution

   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;
      }
   }


推荐答案

用这种方法解决了这个问题:

I solved this problem with this method:

Firt创建一个类:

Firt create a class:

    class BodyContent
  {
    public string ContentType { get; set; }
    public string Body { get; set; }
  }

比:

List<BodyContent> bodies = new List<BodyContent>();
  foreach (AE.Net.Mail.Attachment item in mail.AlternateViews)
  {
    bodies.Add(new BodyContent
    {
      ContentType = item.ContentType,
      Body = item.Body
    });
  }

并且检查有text / html:

And check has "text/html":

string body="";
      BodyContent bodyTemp= bodies.Find(x => x.ContentType == "text/html");
      if (bodyTemp== null)
        body = mail.Body;
      else
        body = bodyTemp.Body;

如果有text / html,body的格式html else body的格式plain

And if has "text/html", body's format html else body's format plain

这篇关于如何使用AE.Net.Mail获取PlainText或Html文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆