Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用AE.Net.Mail获取纯文本或Html文本?_C#_Email_Pop3 - Fatal编程技术网

C# 如何使用AE.Net.Mail获取纯文本或Html文本?

C# 如何使用AE.Net.Mail获取纯文本或Html文本?,c#,email,pop3,C#,Email,Pop3,我正在尝试使用AE.Net.Mail获取电子邮件的纯文本或HTML文本。 我找不到任何文件 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);

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

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.??????                
   }
}
编辑:我找到了这个解决方案

   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;
      }
   }
如果您的邮件是System.Net.Mail,则可以从属性获取邮件正文。它可以是HTML或纯文本,具体取决于IsBodyHtml属性。AlternateViews属性还可能包含邮件正文的其他形式。

如果您的邮件是System.Net.Mail one,则可以从该属性获取邮件正文。它可以是HTML或纯文本,具体取决于IsBodyHtml属性。AlternateViews属性还可能包含消息正文的其他形式。

必须将标题仅设置为false

必须将标题仅设置为false


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

首先创建一个类:

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


如果有text/html,body的格式为html,否则body的格式为plain

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

首先创建一个类:

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


如果有text/html,body的格式是html,否则body的格式是纯的

body=e.Value.alternativeviews.GetHtmlView.body,

body=e.Value.alternativeviews.GetHtmlView.body,

在AE.Net.Mail中,没有IsBodyHtml属性。对于Body属性中的allmessage,我有message的纯文本。对于一封邮件,有两个可选视图:[0]带有ContentType texte/plain[1]带有ContentType texte/html;对于其他邮件,没有可选视图,只有两个附件[0]带有ContentType texte/plain[1]带有ContentType texte/html;对于其他邮件,没有可选视图,也没有附件。如何获取html文本?您可以从内容类型为text/plain的AlternateView获取html正文;您可能需要从ContentStream读取它。AE.Net.Mail中没有用于AlternateView的ContentStream方法!在AE.Net.Mail中,没有IsBodyHtml属性。对于Body属性中的allmessage,我有message的纯文本。对于一封邮件,有两个可选视图:[0]带有ContentType texte/plain[1]带有ContentType texte/html;对于其他邮件,没有可选视图,只有两个附件[0]带有ContentType texte/plain[1]带有ContentType texte/html;对于其他邮件,没有可选视图,也没有附件。如何获取html文本?您可以从内容类型为text/plain的AlternateView获取html正文;您可能需要从ContentStream读取它。AE.Net.Mail中没有用于AlternateView的ContentStream方法!我认为这并不能回答问题。Headers仅仅意味着它只获取电子邮件头,例如from、to、subject、date等。它不下载正文内容或附件。我认为这并不能回答问题。Headers only意味着它只获取电子邮件标题,例如from、to、subject、date等。它不下载正文内容或附件。
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
    });
  }
string body="";
      BodyContent bodyTemp= bodies.Find(x => x.ContentType == "text/html");
      if (bodyTemp== null)
        body = mail.Body;
      else
        body = bodyTemp.Body;