BASE64图像Delphi的Gmail

发布于 2025-01-27 10:58:19 字数 2496 浏览 1 评论 0原文

我知道这个话题已经提出了很多次,但不是专门针对德尔菲的。 我试图通过邮件将生成的QR码作为INLINE IMG发送。 目前,我正在成功地这样做,但仅作为URL:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABqQAAAakCAYAAA..." width="170" height="170">

但是当涉及到Gmail时,它只会增加一个空的正方形。 我查找了许多答案,如何将IMG嵌入到电子邮件中,例如这两个帖子:

base64图像/a>

gmail blocking blocking blocked blocked blocked blocked inline Images in Linine Images in Linke Template

,但我不明白如何在德尔菲内的答案中实现代码。

我还找到了将IMG作为磁盘附件的代码:

procedure TForm1.Button1Click(Sender: TObject);
var
 oSmtp : TMail;
 cid : WideString;
begin
 oSmtp := TMail.Create(Application);

 // Add embedded image and return the unique identifier of the attachment
 cid := oSmtp.AddInline('c:\test.jpg');

 // Set HTML body format
 oSmtp.BodyFormat := 1;
 // Set HTML body
 oSmtp.BodyText := '<html><body>Hello, this is an embedded <img src="cid:' +
 cid + '"> picture.</body></html>';
end;

// i do not use this code it is just an example of what i have found thus far

目前我使用的IMG就是这样:

  HtmlBody = ReplaceStr(HtmlBody, [parameter_img],'<img src="data:image/png;base64,' + StreamToString(imgStream) + '"width="170" height="170"/>');

但是我无法保存IMG,因此我想直接插入Base64String。

Update

我设法在电子邮件中获取附件,但在那里,但是在文本区域中只有一个空白的正方形。

代码的IMG部分和原始电子邮件msg:

<img src="cid:qrcode.png" width="170" height="170" />';
--wpn=_6hoco9kAT3gWlDy6D313EA3BETyyOfe
Content-Type: text/html; charset="windows-1250"
Content-Transfer-Encoding: base64
Content-Disposition: inline

PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIiAiaHR0cDovL3d3dy53My5vcmcvVFIvUkVDLWh0bWw0MC9sb29zZS5kdGQiPjxtZXRhIGh0
dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PXdpbmRv
d3MtMTI1MCI+PGJvZHk+PGltZyBzcmM9Imh0dHBzOi8vbmFpcy1yYXp2b2ouaXBsdXMuc2kvX2Fz
...

--wpn=_6hoco9kAT3gWlDy6D313EA3BETyyOfe
Content-Type: image/png; name="qrcode.png"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="qrcode.png"
Content-ID: qrcode.png


--wpn=_6hoco9kAT3gWlDyD6D313EA3BEyyOfe--

I know this topic has been brought up many times but not specifically for Delphi.
I am trying to send generated qr codes as inline img via mail.
Currently i am succeeding in doing so but only as URL :

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABqQAAAakCAYAAA..." width="170" height="170">

But when it comes to Gmail it only adds an empty square.
I have looked up many answers how to embedde an img to email such as this 2 posts:

Base64 images to gmail

Gmail blocking small embedded inline images in email template

But i do not understand how to implement the code in answers inside Delphi.

I also found code that gets the img as attachment from disk:

procedure TForm1.Button1Click(Sender: TObject);
var
 oSmtp : TMail;
 cid : WideString;
begin
 oSmtp := TMail.Create(Application);

 // Add embedded image and return the unique identifier of the attachment
 cid := oSmtp.AddInline('c:\test.jpg');

 // Set HTML body format
 oSmtp.BodyFormat := 1;
 // Set HTML body
 oSmtp.BodyText := '<html><body>Hello, this is an embedded <img src="cid:' +
 cid + '"> picture.</body></html>';
end;

// i do not use this code it is just an example of what i have found thus far

Currently all i am doing with img is this:

  HtmlBody = ReplaceStr(HtmlBody, [parameter_img],'<img src="data:image/png;base64,' + StreamToString(imgStream) + '"width="170" height="170"/>');

But i can not save the imgs so i want to insert the base64string directly.

UPDATE

I have managed to get the attachment in my email and it is there but in the text area there is only a blank square.

the img part of the code and original email msg:

<img src="cid:qrcode.png" width="170" height="170" />';
--wpn=_6hoco9kAT3gWlDy6D313EA3BETyyOfe
Content-Type: text/html; charset="windows-1250"
Content-Transfer-Encoding: base64
Content-Disposition: inline

PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIiAiaHR0cDovL3d3dy53My5vcmcvVFIvUkVDLWh0bWw0MC9sb29zZS5kdGQiPjxtZXRhIGh0
dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PXdpbmRv
d3MtMTI1MCI+PGJvZHk+PGltZyBzcmM9Imh0dHBzOi8vbmFpcy1yYXp2b2ouaXBsdXMuc2kvX2Fz
...

--wpn=_6hoco9kAT3gWlDy6D313EA3BETyyOfe
Content-Type: image/png; name="qrcode.png"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="qrcode.png"
Content-ID: qrcode.png


--wpn=_6hoco9kAT3gWlDyD6D313EA3BEyyOfe--

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

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

发布评论

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

评论(1

或十年 2025-02-03 10:58:19

首先,我认为问题是:PCFET0NUWVBFIGH0BWWGUFVCTELDICTICL
由于它看起来不像IVBOR开头的PNG的基本64代码。

但是问题在这里:content-id:qrcode.png

在设置content-id时,您必须小心,因为在某些版本中,请简单地使用引号设置它是不够的,您必须将其设置添加&lt;&gt;像这样:content-id:&lt; qrcode.png&gt;

因此,结果就是想要的。

At first i thought the issue is this : PCFET0NUWVBFIGh0bWwgUFVCTElDICItL
since it does not look like base64 code of png which starts with iVBOR.

But the issue was here : Content-ID: qrcode.png

When setting Content-ID you have to be carefull since in some versions simply setting it with quotation marks is not enough and you have to set it with adding <> like so : Content-ID: <qrcode.png>.

With this the result was as wanted.

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