[W1][Codeunit][4509][Email - Outlook API Helper] OnBeforeInsert event in CreateEmailInboxFromJsonObject exposing the source JSON payload
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
Why do you need this change?
When emails are retrieved through the Email Connector v4 RetrieveEmails flow, CreateEmailInboxFromJsonObject parses the Microsoft Graph message JSON but only maps a subset of fields onto the Email Inbox record. Notably, the recipient collections that Graph returns (toRecipients, ccRecipients, bccRecipients) are not transferred to the created Email Message/Email Inbox — the message is built with EmailMessage.Create('', Subject, Body, HTMLBody, true), so GetRecipients is always empty for retrieved mail.
As a result, any app that logs retrieved emails cannot obtain the actual To/Cc recipients of a retrieved message. There is currently no seam to recover them: the connector codeunits are Access = Internal, the OAuth token is a private [NonDebuggable] SecretText, and no event is raised around the insert. The only workaround today is to independently re-query Microsoft Graph with a separate app registration, which forces every customer to create and consent to an Azure AD app purely to read data Business Central already fetched.
An integration event that exposes the raw source JSON just before the Email Inbox record is inserted would let subscribers read any property Graph returned (recipients, importance, categories, internetMessageId, etc.) and/or enrich the Email Inbox record — without Microsoft having to add every field to the standard mapping, and without customers standing up a duplicate Graph integration. This is a general-purpose extensibility point that benefits any partner building mail-logging, archiving, or CRM scenarios on top of the email retrieval feature.
Describe the request
Please add an OnBefore-insert integration event in Codeunit 4509 "Email - Outlook API Helper", in the local procedure CreateEmailInboxFromJsonObject, raised immediately before EmailInbox.Insert();. The event should pass the Email Inbox record by var (so subscribers can set additional/custom fields before it is persisted) and the source EmailJsonObject for the message (so subscribers can read any property returned by Graph, including the recipient arrays that are not currently mapped).
This is a "before we insert a line to update specific fields" hook, which is listed as a valid use in Types of events for extensibility. It is a standard IntegrationEvent (not an IsHandled/skip event) — it only notifies and allows enrichment; it does not override or suppress the insert.
Provide an implementation (optional)
- I will provide the implementation for this extensibility request
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open Codeunit 4509 "Email - Outlook API Helper" and locate the local procedure CreateEmailInboxFromJsonObject. Start at the existing EmailInbox.Insert() call and add the requested integration event immediately before it, passing the Email Inbox record by var and the source EmailJsonObject. Done means subscribers can enrich the record or inspect the original JSON before insertion.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100