-1

Scenario: I have a delphi 7 application and i have a function that send mail's with embedded images using base64 encoding, and MIME types.

The body 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

Problem: The email comes to me in my Gmail with a gray box instead of a image.

What i've tried: I tried to change the MIME: Content-Type and etc, to many types such as text/html and image/jpeg, alternative/mixed etc...

What do i want: I want to simply send a email that can have a signature(some text) containing a visible image in base64 properly.

Paulo Roberto Rosa
  • 3,071
  • 5
  • 28
  • 53

1 Answers1

2

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.

Paulo Roberto Rosa
  • 3,071
  • 5
  • 28
  • 53