通过SmtpClient发送的电子邮件不显示图像

本文关键字:显示 显示图 图像 电子邮件 SmtpClient 通过 | 更新日期: 2023-09-27 18:01:50

下面的代码生成一封电子邮件,其中图像通过webmail客户端(如gmail)可见,但通过thunderbird或outlook客户端不可见。在这些客户端中可以看到一个断开的链接,并且由于某种原因它没有提示我加载图像。当从另一个客户端转发相同的电子邮件时,它确实提示我加载图像,一切都按照预期运行。

 class Program 
{
    static void Main(string[] args)
    {
        var mesg = new MailMessage("destination@somewhere.com","from@somewhere.com");
        mesg.Body = "<img src='http://localhost/images/bangs.JPG' />";
        mesg.Subject = "Image Spike Test";
        mesg.IsBodyHtml = true;
        var client = new SmtpClient("localhost");
        client.Send(mesg);
    }
}

这是由这段代码产生的电子邮件源。

MIME-Version: 1.0
From: destination@somewhere.com
To: from@somewhere.come
Date: 9 Jul 2011 09:25:08 -0500
Subject: Image Spike Test
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
<img src=3D'http://localhost/images/bangs.JPG' />

通过SmtpClient发送的电子邮件不显示图像

嗯,如果你发送这样的邮件,你的电子邮件阅读器将不得不去register.cwh.com请求图像。这将告诉register.cwh.com何时,从哪里,电子邮件被阅读。Outlook和其他电子邮件客户端保护您的隐私,不检索图像。我有点惊讶GMail会加载它们。

正确的解决方法是将图像作为附件发送。Outlook将显示附件中的图像。