'Base64 images to gmail in Delphi
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:
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--
Solution 1:[1]
You can pipe the output of any command to kafka-console-producer or kcat
my-command
#!/usr/bin/env python
print("hello world")
$ chmod +x my-command
$ ./my-command | kafka-console-producer --topic foobar --bootstrap-server localhost:9092
$ kafka-console-consumer --topic foobar --from-beginning --bootstrap-server localhost:9092
hello world
Keep in mind, this will be line-delimited strings, so if you want something more robust, or are dealing with binary data, you'll need to attach a stream to the process's output stream file-descriptor (rather than a separate output file) via code. For example see this post, then translate the tail command to something else.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OneCricketeer |
