简单的电子邮件预览

时间:2012-10-31 21:40:50

标签: c#

我正在努力开发一种有助于训练Spamassassin的实用工具。我在顶部填写了主题,发件人等的列表视图,并在底部有两个预览/查看窗格,一个文本框和一个邮件查看器。我会将邮件标记为垃圾邮件或火腿(如果是)。所以我必须先看看它们。

我可以在文本框中轻松显示消息来源。但是,我无法成功显示丰富的邮件消息。我尝试了webbrowser控件,它很好地显示了一些消息,并且没有显示 - 显示为消息源 - 最多。

我完全不知道如何显示邮件消息。有没有特殊组件/控件?我可以使用Win7的内置预览吗?或者我可以在自己的实用程序上使用Explorer的预览机制吗?抱歉,目前我无法添加任何代码,因为问题与任何代码行无关。但是。

2 个答案:

答案 0 :(得分:1)

问题是您的电子邮件中嵌入了很难显示的附件。您可以编写一些代码来解决这个问题,但它的成本很高,而且可能无法满足您的需求。

几年前,我遇到过类似的问题。那时候我使用了类似的东西http://forums.asp.net/t/1350519.aspx

更新:需要在PC上安装Outlook。使用Outlook Express可以完成类似的操作,您只需要找到COM dll即可。

答案 1 :(得分:0)

我使用https://github.com/andyedinborough/aenetmail中的 AE.Net.Mail 进行了一些测试,效果非常好!

重新访问的代码:

            string htmlBody = "", textBody = "";

            MailMessage msg = new MailMessage();
            msg.Load(cellBody.Value.ToString(), false); // cellBody.Value.ToString() is raw message

            if (msg.Body != null)
            {
                switch (msg.ContentType)
                {
                    case "text/plain":
                        textBody = msg.Body;
                        break;
                    case "text/html":
                        htmlBody = msg.Body;
                        break;
                }
            }


            if(msg.AlternateViews.Count > 0)
            {
                foreach (Attachment alternateView in msg.AlternateViews)
                {

                    switch (alternateView.ContentType)
                    {
                        case "text/plain":
                            textBody = alternateView.Body;
                            break;
                        case "text/html":
                            htmlBody = alternateView.Body;
                            break;
                    }
                }
            }

            if(msg.Attachments.Count > 0)
            {
                foreach (Attachment attachment in msg.Attachments)
                {

                    switch (attachment.ContentType)
                    {
                        case "text/plain":
                            textBody = attachment.Body;
                            break;
                        case "text/html":
                            htmlBody = attachment.Body;
                            break;
                        case "message/rfc822":
                            break;
                    }
                }
            }

            textBody = "<pre>" + textBody + "</pre>";

            if (htmlBody == "")
                webBrowser1.DocumentText = textBody;
            else
                webBrowser1.DocumentText = htmlBody;


            textBox1.Text = cellBody.Value.ToString();
相关问题