我想使用AE.Net.Mail获取纯文本或HTML文本的电子邮件。 我找不到任何文档。如何使用AE.Net.Mail获取PlainText或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;
}
}
在AE.Net.Mail中,没有'IsBodyHtml'属性。对于'Body'属性中的所有消息,我都有纯文本的消息。 对于一个消息,存在2'AlternateViews': [0]与'ContentType' “texte /纯” [1]与'ContentType' “texte/HTML” 对于其他消息没有'AlternateViews'但2'Attachements' 对于其他消息,没有'AlternateView's并且没有'Attachements'。'''''''''''''''''''' 我如何获取html文本? – LeMoussel
您可以从其“ContentType”为“text/plain”''AlternateView'的HTML主体获取;你可能需要从'ContentStream'中读取它。 – Douglas
AE.Net.Mail中的'AlternateView'没有'ContentStream'方法! – LeMoussel