Prior to APEX 21.2, when you add any attachments to APEX email using apex_mail.add_attachment procedure, then those attachments are always added with Content-Disposition as attachment. This behavior can be verified when we view the received emails as plain text, For e.g. refer to the below screenshot of an email taken using the "Show Original" option in the Gmail web client.
APEX 21.2 has introduced a new feature that enables us to send attachments as inline attachments. There is a new parameter p_content_id added to apex_mail.add_attachment procedure. We can specify content_id for attachments and we can use this content_id to refer to the image in cid: scheme in img tags of HTML emails.
In one of my previous blogposts, Including Images in Oracle APEX Emails, I have discussed a few options using which we can include images in emails. One of the options is attaching images to an email and referring to attached images by file name in cid: scheme. This works in desktop email clients, but not in web email clients like Gmail. The reason is, APEX was always using Content-Disposition: attachment; for all attachments and there was no way to change it. Now, in APEX 21.2, when we specify p_content_id for any attachments, APEX will specify Content-Disposition as inline for those attachments and it will also specify the Content-ID. This change enables embedding images in email content in more reliably way and it would work in all email clients that support cid: scheme approach.
So, let's build a quick demo page to test this new feature.
- Create a new page and add a text item. In the demo, I have created page 42 and the item name is P42_EMAIL_TO. We will use this text item to enter the email address.
- Add button next to the text item. Ensure, Button > Behavior > Action is set as "Submit Page". In the demo, I have created a button with the name SEND_EMAIL.
- Upload any image file that you want to include in the emails to the "Static Application Files" section. In the demo, I have uploaded a file with the name ironman.jpg
- Create a page process as below
- Name: Testing Inline Attachments (or any other proper name)
- Type: Execute Code
- Server-side Condition
- When Button Pressed: Select SEND_EMAIL button.
- Language: PL/SQL
- PL/SQL Code: As below
Here is the link for the demo.