How To…Email HTML messages with inline images

Question

“Is it possible to send an email with an HTML body including inline images?”

Solution

Starting with RB 14, it is possible to send email from ReportBuilder in HTML format and also include inline images inside the email message.

To do so, simply add the HTML source you would like as the email message to the EmailSettings.BodyHtml property (leaving the EmailSettings.Body property blank). For each image you would like to add, use the format “cid:[ImageName]” if you would like to attach the image file or a valid URL if the image in on-line.

Attached image example HTML: <img src=”cid:Image.jpg”>

 

Once the BodyHtml property has been defined, add the file location of any images you would like included to the EmailSettings.BodyHtmlAttachments property. This will attach the image(s) to the email message so they will display inline inside the email message.

Notes:

This feature is only available with the Indy 10 or the Extended MAPI plugins (no preview). Include the ppSMTPIndy10 or ppExtendedMAPI files respectively in the “uses” clause to register the plugin to be used.

Download: EmailHtmlInlineImage.zip

Sample Delphi code:

procedure TForm1.SetupEmail;
begin

  ppReport1.EmailSettings.Enabled := True;
  ppReport1.EmailSettings.PreviewInEmailClient := False; //Inline images do not currently function when previewing in Outlook

  ppReport1.EmailSettings.BodyHtml.Assign(Memo1.Lines);  //Add HTML email body
  ppReport1.EmailSettings.BodyHtmlAttachments.Add(ExtractFilePath(Application.ExeName) + 'image.jpg');  //Add image reference

  ppReport1.EmailSettings.Recipients.Add('User@SomeServer.com');  //Assign recipient(s)

  ppReport1.EmailSettings.Subject := 'Subject';

end;