发送到电子邮件时未显示图像

发布于 2025-02-10 04:46:55 字数 1290 浏览 4 评论 0原文

string html = "<img src=data:image/png;base64,i0KGgAD34DtaA..........*>"; //*very long
SensMail(mailaddress,html, System.Text.Encoding.UTF8);

public static void SensMail(string sendTo, string body, System.Text.Encoding enCode)
{
            string emailaddress = "[email protected]";
            string password = "it's secret";
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient();
            mail.From = new MailAddress(sendTo);
            mail.To.Add(sendTo);
            mail.BodyEncoding = enCode;
            mail.IsBodyHtml = true;
            mail.Subject = "subject";
            mail.Body = body;
            SmtpServer.UseDefaultCredentials = false;
            NetworkCredential NetworkCred = new NetworkCredential(emailaddress,password);
            SmtpServer.Credentials = NetworkCred;
            SmtpServer.EnableSsl = true;
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.Send(mail);
}

为什么不显示图像?

我试图发送给两个不同的电子邮件提供商,但没有成功。

这是出于安全原因发生的吗?

该问题如何解决?

在html中确实有效,您会看到图像。

string html = "<img src=data:image/png;base64,i0KGgAD34DtaA..........*>"; //*very long
SensMail(mailaddress,html, System.Text.Encoding.UTF8);

public static void SensMail(string sendTo, string body, System.Text.Encoding enCode)
{
            string emailaddress = "[email protected]";
            string password = "it's secret";
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient();
            mail.From = new MailAddress(sendTo);
            mail.To.Add(sendTo);
            mail.BodyEncoding = enCode;
            mail.IsBodyHtml = true;
            mail.Subject = "subject";
            mail.Body = body;
            SmtpServer.UseDefaultCredentials = false;
            NetworkCredential NetworkCred = new NetworkCredential(emailaddress,password);
            SmtpServer.Credentials = NetworkCred;
            SmtpServer.EnableSsl = true;
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.Send(mail);
}

Why is the image not displayed ??

I tried to send to two different email providers, without success.

Is this happening for security reasons?

How can this problem be solved?

In HTML it does work and you see the image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭ゆ眷念 2025-02-17 04:46:55

Outlook不了解Base64图像。有两种可能的方法:

  1. 将图像文件上传到任何Web服务器,然后在HTML主体中使用图像URL进行该图像。请注意,Outlook可能会自动阻止外部链接(甚至是图像)。

  2. 您可以将图像文件添加为附件,然后使用cid前缀img标签。请参阅电子邮件中的内联映像有关更多信息。

Outlook doesn't understand base64 images. There are two possible ways:

  1. Upload the image file to any web server and then use the image URL in the HTML body for that image. Be aware, Outlook may block external links (even for images) automatically.

  2. You may add an image file as an attachment and then use the cid prefix for the img tag. See Send inline image in email for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文