I have found the solution by myself, and the problem was with the MIME.
Before, i was sending the email with only one MIME type that was: Content-type: text/html
And now, i created a TMimeMess
containing TMimepart
's as Multiparts
:
var
m : TMimemess;
SubPartSignature,
mix ,
rel : TMimepart;
m := TMimemess.create;
mix := m.AddPartMultipart('mixed',nil);
rel := m.AddPartMultipart('related', mix);
m.AddPartHTML(FstlMensagemHTML, mix);//note that the FstlHTMLMessage is the body html of the email
SubPartSignature := m.AddPartHTMLBinary(cprdbutils.getBlob_StringStream(dts.FieldByName('bl_logo')), 'logo.jpg', 'CidKey', rel);
rel.AddSubPart;
rel.AssignSubParts(SubPartSignature);
The function cprdbutils.getBlob_StringStream(dts.FieldByName('bl_logo'))
returns the Stream of the image from the database blob field.
And the function AddPartHTMLBinary()
is here:
function TMimeMess.AddPartHTMLBinary(const Stream: TStream; const FileName, Cid: string; const PartParent: TMimePart): TMimepart;
begin
Result := AddPart(PartParent);
Result.DecodedLines.LoadFromStream(Stream);
Result.MimeTypeFromExt(FileName);
Result.Description := 'Included file: ' + FileName;
Result.Disposition := 'inline';
Result.ContentID := Cid;
Result.FileName := FileName;
Result.EncodingCode := ME_BASE64; //this is a constant containing base64
Result.EncodePart;
Result.EncodePartHeader;
end;
And here is the body HTML of the email:
the message
<hr>
<img width=213 height=120 src="cid:CidKey"/> <!-- Important! here is the cid reffered to the cid that i previously set on the code! -->
<hr>
some text
Now it works perfectly.