Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

HTML Files and Indy

edited September 2005 in Devices
I have this problem, where I have been trying to send the HTML files
generated from ExtraDev(By setting the device type to htmlfile) through Indy
in an email.
Problem #1 - I have to embed the HTML in the email, instead of attaching,
because I am getting multiple .jpg files, and if I try to attach the HTML in
the email (which I would prefer to do), I get a list of all the related
files attached also (I have to send them separately). Is there a way to get
one single file?
Problem #2 - After much back and forth, I got this response from the Indy
Team B member -
I am trying to add text + send (or attach) the HTML + add unrelated files.
Can anyone help me figure out how to do all this?

Your HTML content is not referencing the attachments properly. As stated in
the blog that I directed you to earlier, the "src" atribute of the image tag
MUST use the "cid" protocol. In other words, change this:

image

To this instead:

image

All I can tell you is that the HTML data is wrong for email. Since you are
loading the HTML from a file, the HTML appears to be generated such that it
is meant to be displayed from a file and thus the images are assumes to be
stored in the same folder as the HTML file. That will not work for email.
You will have to adjust the links inside the generated HTML accordingly.
When I made the appropriate changes to the email data that you showed, I had
no troubles viewing the images in an email properly.


Not Indy specifically. As-is, it is not suitable for email in general.

Comments

  • edited September 2005
    You can use the DeviceExportToMail procedure in the TXRB unit. This will generate an HTML
    email. You can also check the code to see how this is done if you need more control over
    the sending process.

    James Waler
    Waler Ltd
    http://www.waler.com
  • edited September 2005
    I have added these to lines just before the report print command:
    xtraDev.HTML.BaseURL := 'CID:';
    xtraDev.HTML.SingleFileOutput := True;

    (note : I still get one html file, and 11 .jpg files)

    I changed my email code to :
    procedure TdlgEmail.CreateHTMLEmail(rList, uList, txtBody: TStrings);
    var
    i : integer;
    iRelatedPart : integer; // multipart/related part
    iAlternativePart : integer; // multipart/alternative part
    Bdy: TIdText;
    Img: TIdAttachmentFile;
    begin
    iRelatedPart := -1;
    iAlternativePart := -1;
    emMessage.ContentType := 'multipart/mixed';

    if (rList.Count > 0) and (uList.Count > 0) then
    begin
    with TIdText.Create(emMessage.MessageParts, nil) do
    begin
    ContentType := 'multipart/related;type="multipart/alternative"';
    iRelatedPart := Index;
    end;
    end;

    if (rList.Count > 0) or (uList.Count > 0) then
    begin
    with TIdText.Create(emMessage.MessageParts, nil) do
    begin
    ContentType := 'multipart/alternative';
    ParentPart := iRelatedPart;
    iAlternativePart := Index;
    end;
    end;

    Bdy := TIdText.Create(emMessage.MessageParts);
    Bdy.ContentType := 'text/plain';
    Bdy.Body.Assign(txtBody);
    Bdy.Body.Add('This mail was sent in html format. Please open the attached
    file.');
    Bdy.ParentPart := iAlternativePart;


    Bdy := TIdText.Create(emMessage.MessageParts);
    Bdy.ContentType := 'text/html';
    Bdy.Body.LoadFromFile(UserFPath + 'rpt001.htm');
    bdy.ParentPart := iAlternativePart;

    for I := 0 to rList.Count - 1 do
    begin
    Img := TIdAttachmentFile.Create(emMessage.MessageParts, rList[I]);
    Img.ContentDisposition := 'inline';
    Img.ContentType := 'image/jpeg';
    Img.ExtraHeaders.Values['Content-ID'] := ExtractFileName(rList[I]);
    img.ParentPart := iRelatedPart;
    end;
    for I := 0 to uList.Count - 1 do
    CreateAttachment(uList[i]);
    end;

    HTML part looks great.
    However.
    If I attach an unrelated file, no text, the file is attached, but I have no
    HTML in the resulting email.
    The text never shows.
    If I add both text and an unrelated file, I can see the HTML, and the file
    gets attached, but I still don't see the text.
  • edited September 2005
    The SingleFileOutput applies to the HTML files only. Any images will always be created
    separately. You might want to try the Indy groups since your issues are now with
    sending the email.

    James Waler
    Waler Ltd
    http://www.waler.com
This discussion has been closed.