Convert Email Draft to Email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 11:00 AM
I have a requirement to create an email and attach a file to it prior to sending. I thought the best approach might be to use the Draft Email (sys_email_draft) table to 'stage' the email before sending, as opposed to creating a record on the sys_email table and manipulating the 'type' to 'send-ignored' then 'send-ready' once the attachment has been added. I cannot seem to find an elegant solution using an event or triggered notification in which I can programmatically attach a file to the email before it gets sent. For context, I am dynamically generating the file via the MS Excel spoke, and once done, I need to send an email with that new attachment to an external recipient.
The OOB 'Compose Email' button in the workspace opens a modal on the 'record' page with the 'Draft Email Page' variant. The page utilizes the 'NOW Email Client Composer' component which contains the 'Send Email' button, which appears to be embedded in the component itself, as opposed to being a separate UI or Declarative action
I cannot determine what the 'Send Email' button is actually doing to convert the email from a draft to a record on the sys_email table which is then sent. There are no Business Rules or Flows or Scheduled jobs I can tell which are executing to convert the record, so I have to assume code is embedded in the component.
I am looking for some insight into how I might go about doing this conversion from draft to email. Perhaps there is an OOB script include or other logic called from the component which accomplishes this?
Any thoughts/ideas/insights are greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2025 03:51 AM
Hey @Community Alums
I am trying to implement the email functionality with custom component.
- Generate an empty draft : Use GlideRecord to create a sys_email_draft record with fields like subject, body, and recipient for user updates.
- Capture user inputs and update draft , Linking attachments to draft email and referencing in draft email attachments table.
- Send email logic :
- convert the draft to a sys_email record via GlideRecord.
Copy attachment references from sys_email_draft_attachment to sys_email_attachment.
Sending Email. - Deleting the draft upon successful creation of email records and linking attachments with the new email record.
- Update the sys_email record state to send-ready. Hoping that the email engine processes and sends sys_email records with state=send-ready through the SMTP server.
Reason for taking this approach
This approach ensures control over the email state and attachment processing. Directly using sys_email risks sending the email before all attachments are processed, as the transition from send-ready to sent is automatic. Using sys_email_draft avoids this issue.
Questions
1 Can you validate my approach, If not what is the workflow for converting the draft to email.
2 What specific internal script or API is responsible for transitioning sys_email_draft to sys_email within the NOW Email Client Composer?