1

Using clever internet components I was able to read email has picture inserted into the body and the result is this html:

email with photo<div dir="ltr"><div><img src="cid:ii_kctxj0az0" width="192" height="192"><br><br></div></div>

Problem I need full url for this image to display in online web page so how I can do this ? answer can be in general code.

Code:

var
  i: Integer;
  result: string;
begin
  if (clPop31.Active) then Exit;

  clPop31.Server := 'mailserver.com';
  clPop31.Port := 110;
  clPop31.UserName := 'user@server.com';
  clPop31.Password := 'xxxxxxxxxxx';

  lbMessages.lines.Clear();

  clPop31.Open();
  try
    for i := 1 to clPop31.MessageCount do begin
      clPop31.Retrieve(i);

      lbMessages.lines.Add(result + clMailMessage1.Subject + clMailMessage1.MessageText.text);
    end;
  finally
    clPop31.Close();
  end;

  ShowMessage('Done');

end;
zac
  • 4,495
  • 15
  • 62
  • 127

1 Answers1

2

There is no online URL for embedded resources.

In an HTML-encoded email, when an <img> element (or other resource-related element, like <bgsound>, <audio>, <video>, etc) uses a cid: URL for its source, it is referring to an email attachment that is linked to the HTML. For instance, if the HTML is inside a MIME multipart/related part, then attachments related to the HTML are also inside that same MIME part.

So, for example, for an <img> element whose src attribute is "cid:ii_kctxj0az0", it is referring to a linked email attachment whose Content-ID is ii_kctxj0az0. The <img> element gets its picture data directly from that attachment, not from an external source that is online somewhere.

So, if you want to use the resource data in an online web page, you will have to extract the data from the referred attachment, and then either:

  1. save the data to a file somewhere online as needed, so you will have an online URL with which a webpage can refer to the data.

  2. or, modern web browser's support data: URLs, which you can use to embed the data directly in the HTML itself.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • So to display this email + image later in a web page I download the attachment then upload it to online server then get the url and update the email before I send it/post it to the web page ? or there is another way ? – zac Jul 20 '20 at 18:24
  • 1
    "*So to display this email + image later in a web page I download the attachment then upload it to online server then get the url and update the email before I send it/post it to the web page*" - Yes. "*or there is another way ?*" - if you don't want to upload the image file somewhere, have a look at using a [`data:` URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) directly in the HTML itself. – Remy Lebeau Jul 20 '20 at 18:34
  • the data url are too large, I tried from your code [here](https://stackoverflow.com/questions/41633096/convert-a-jpg-png-gif-etc-as-a-64base-string) but the my png was not displayed after I used this format ` ` – zac Jul 20 '20 at 19:09
  • 1
    @Wel [Data protocol URL size limitations](https://stackoverflow.com/questions/695151/) – Remy Lebeau Jul 20 '20 at 19:31