gpt4 book ai didi

c# - 如何使用AE.Net.Mail获取PlainText或HTML文本?

转载 作者:太空宇宙 更新时间:2023-11-03 18:13:14 25 4
gpt4 key购买 nike

我正在尝试使用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;
}
}

最佳答案

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

首先创建一个类:

    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”:

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


如果具有“ text / html”,则正文的格式为html,否则为正文的格式

关于c# - 如何使用AE.Net.Mail获取PlainText或HTML文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com