【问题标题】:Embedded image in mail body is not displayed in webbrowser control in winforms邮件正文中的嵌入图像未显示在 winforms 的 webbrowser 控件中
【发布时间】:2016-01-20 07:40:28
【问题描述】:

我想将 Outlook 邮件正文的内容放入 winforms 中的 webbrowser 控件中。 如果我使用以下代码,则会显示所有内容,但不显示页面中的图像。 我正在使用 Outlook 2013 和 VS2012。

webBrowser1.DocumentText = mail.HTMLBody;

我检查了 html,它显示如下: 它显示如下:

<img id=\"Picture_x0020_7\" src=\"cid:image002.png@01D10B5C.06CC63D0\" width=\"904\" height=\"768\">

由于我想在项目中实现它,我无法按照此处的建议将邮件正文保存在本地:how to get embed image from current outlook email with c#?^]

非常感谢任何帮助。

【问题讨论】:

    标签: c# winforms outlook


    【解决方案1】:

    以下是您需要做的:

        private void sendInlineImg() {
        MailMessage mail = new MailMessage();
        mail.IsBodyHtml = true;
        mail.AlternateViews.Add(getEmbeddeImage());
        mail.From = new MailAddress("yourAddress@yourDomain");
        mail.To.Add("recipient@hisDomain");
        mail.Subject = "yourSubject";
        //YourSMTPClient.Send(mail); //* Set your SMTPClient before!
    }
    private AlternateView getEmbeddeImage() {
        string yourFile = "c:/header.png";
        LinkedResource inline = new LinkedResource(yourFile);
        inline.ContentId = Guid.NewGuid().ToString();
        string htmlBody = @"<img src='cid:" + inline.ContentId + @"'/>";
        AlternateView alternateView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
        alternateView.LinkedResources.Add(inline);
        return alternateView;
    }
    

    【讨论】:

      【解决方案2】:

      您可以在邮件项目中找到以附件形式存储的引用嵌入图像。您可以将它们保存在磁盘上或上传到任何 Web 服务器,然后将代码中 &lt;img/&gt; 标记的 src 属性内容替换为新值,以便浏览器正确显示图像。

      或者只是尝试使用 HTML 文件格式保存邮件项目。 MailItem 类的SaveAs 方法将Microsoft Outlook 项保存到指定路径,并以指定文件类型的格式保存。如果未指定文件类型,则使用 MSG 格式 (.msg)。请注意,您需要为 Type 参数使用 olHTML 值。

      【讨论】:

      • @DigambarMalla 你完成了吗?
      • @coder771,我使用下面的控件来解决这个问题。 yarte.codeplex.com
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 2021-10-12
      相关资源
      最近更新 更多