---
id: object/codeunit/8901
type: object
title: Codeunit 8901 "Email"
summary: Codeunit 8901 "Email" in System Application (System.Email). 53 public procedures, 15 events. Present since at least BC23, still in BC30, changed in BC24-29.
tier: official
language: en
tags:
  - codeunit
  - system application
versions:
  introduced: null
  last_changed: "29"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 5fdf9cb3c1b311d4005be368cee27ff45b0e8fc0b9b2abfa6c67691339979adc
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/Email/src/Email/Email.Codeunit.al
    title: src/System Application/App/Email/src/Email/Email.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/11612
    - change/bcapps/8771
object_type: codeunit
object_id: 8901
name: Email
namespace: System.Email
app: System Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 68
  events: 15
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 6
  calls: 2
  called_by: 22
  implements: 0
---

# Codeunit 8901 "Email"

> Codeunit 8901 "Email" in System Application (System.Email). 53 public procedures, 15 events. Present since at least BC23, still in BC30, changed in BC24-29.

System Application · System.Email · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/Email/src/Email/Email.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Access | Public |

## Events published

- `OnShowSource(SourceTableId: Integer; SourceSystemId: Guid; var IsHandled: Boolean)` (integration): Integration event to show an email source record.
  - subscribers: [Codeunit 8898 "Map Email Source"](../codeunit/8898.md) OnGetPageForSourceRecord
- `OnBeforeFilterRemovedSourceRecords(var EmailRelatedRecord: Record "Email Related Record")` (integration): Integration event that allows applying additional filtering to related source records before they are shown.
- `OnAfterAddRelation(EmailMessageId: Guid; TableId: Integer; SystemId: Guid; var RelatedSystemIds: Dictionary of [Integer, List of [Guid]])` (integration): Integration event to add additional relations based on added relation to emails.
  - subscribers: [Codeunit 5956 "Contact Business Relation"](../codeunit/5956.md) OnEmailAddedRelation
- `OnAfterRemoveRelation(EmailMessageId: Guid; TableId: Integer; SystemId: Guid)` (integration): Integration event to execute code when relation is removed from email.
- `OnGetBodyForTestEmail(Connector: Enum "Email Connector"; AccountId: Guid; var Body: Text)` (integration): Integration event to override the default email body for test messages.
  - subscribers: [Codeunit 4513 "SMTP Connector Impl."](../codeunit/4513.md) SetTestEmailBody
- `OnFindRelatedAttachments(SourceTableId: Integer; SourceSystemID: Guid; var EmailRelatedAttachments: Record "Email Related Attachment")` (integration): Integration event to get the names and IDs of attachments related to a source record.
  - subscribers: [Codeunit 8898 "Map Email Source"](../codeunit/8898.md) FindRelatedAttachments
- `OnGetAttachment(AttachmentTableID: Integer; AttachmentSystemID: Guid; MessageID: Guid)` (integration): Integration event that requests an attachment to be added to an email.
  - subscribers: [Codeunit 8898 "Map Email Source"](../codeunit/8898.md) InsertAttachment
- `OnEnqueuedInOutbox(MessageId: Guid)` (integration): Integration event to implement additional validation after the email message has been enqueued in the email outbox.
- `OnEnqueuedReplyInOutbox(MessageId: Guid)` (integration): Integration event to implement additional validation after the email message has been enqueued in the email outbox.
- `OnAfterEmailSent(SentEmail: Record "Sent Email")` (integration): Integration event that notifies senders when the email has been sent successfully. This event is isolated.
- `OnAfterEmailSendFailed(EmailOutbox: Record "Email Outbox")` (integration): Integration event that notifies senders when the email has been sent unsuccessfully. This event is isolated.
  - subscribers: [Codeunit 6753 "Send Reminder Event Handler"](../codeunit/6753.md) UpdateAfterEmailSendFailed
- `OnBeforeOpenEmailEditor(var EmailMessage: Codeunit "Email Message"; IsNewEmail: Boolean)` (integration): Integration event that allows updating of the email message before the email editor opens.
- `OnBeforeSendEmail(var EmailMessage: Codeunit "Email Message")` (integration): Integration event that allows updating of the email message before the email is queued for sending.
- `OnBeforeReplyEmail(var EmailMessage: Codeunit "Email Message")` (integration): Integration event that allows updating of the email message before the email is queued for replying.
- `OnBeforeGetEmailAttachmentsByEmailScenarios(var EmailScenarioAttachments: Record "Email Scenario Attachments")` (integration): Integration event that allows adding filters to the Email Scenario Attachments before they are retrieved.

## Procedures

- `SaveAsDraft(EmailMessage: Codeunit "Email Message")`: Saves a draft email in the Outbox.
- `SaveAsDraft(EmailMessage: Codeunit "Email Message"; var EmailOutbox: Record "Email Outbox")`: Saves a draft email in the Outbox.
- `SaveAsDraft(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailOutbox: Record "Email Outbox")`: Saves a draft email in the Outbox.
- `Enqueue(EmailMessage: Codeunit "Email Message")`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; NotBefore: DateTime)`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; EmailScenario: Enum "Email Scenario")`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; EmailScenario: Enum "Email Scenario"; NotBefore: DateTime)`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary)`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary; NotBefore: DateTime)`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector")`: Enqueues an email to be sent in the background.
- `Enqueue(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; NotBefore: DateTime)`: Enqueues an email to be sent in the background.
- `Send(EmailMessage: Codeunit "Email Message"): Boolean`: Sends the email in the current session.
- `Send(EmailMessage: Codeunit "Email Message"; EmailScenario: Enum "Email Scenario"): Boolean`: Sends the email in the current session.
- `Send(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary): Boolean`: Sends the email in the current session.
- `Send(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"): Boolean`: Sends the email in the current session.
- `Reply(EmailMessage: Codeunit "Email Message"; ExternalId: Text; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"): Boolean` (obsolete 26.0: Replaced by Reply without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter.): Sends a reply to an external message id in the foreground.
- `ReplyAll(EmailMessage: Codeunit "Email Message"; ExternalId: Text; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"): Boolean` (obsolete 26.0: Replaced by ReplyAll without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter.): Sends a reply to an external message id to all recipients on that email in the foreground.
- `EnqueueReply(EmailMessage: Codeunit "Email Message"; ExternalId: Text; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailOutbox: Record "Email Outbox")` (obsolete 26.0: Replaced by EnqueueReply without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter.): Sends a reply to an external message id in the background.
- `EnqueueReplyAll(EmailMessage: Codeunit "Email Message"; ExternalId: Text; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailOutbox: Record "Email Outbox")` (obsolete 26.0: Replaced by EnqueueReplyAll without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter.): Sends a reply to an external message id to all recipients on that email in the foreground.
- `Reply(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"): Boolean`: Sends a reply to an external message id in the foreground.
- `ReplyAll(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"): Boolean`: Sends a reply to an external message id to all recipients on that email in the foreground.
- `EnqueueReply(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailOutbox: Record "Email Outbox")`: Sends a reply to an external message id in the background.
- `EnqueueReplyAll(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailOutbox: Record "Email Outbox")`: Sends a reply to an external message id to all recipients on that email in the foreground.
- `RetrieveEmails(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailInbox: Record "Email Inbox")` (obsolete 26.0: Replaced by RetrieveEmails with an additional Filters parameter of type Record "Email Retrieval Filters".): Retrieves emails from the email account.
- `RetrieveEmails(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailInbox: Record "Email Inbox"; var Filters: Record "Email Retrieval Filters" temporary)`: Retrieves emails from the email account.
- `GetMailFolders(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailFolders: Record "Email Folders" temporary)`
- `FindRetrievedEmail(EmailAccountId: Guid; ExternalMessageId: Text; var EmailInbox: Record "Email Inbox"): Boolean`: Finds an email that was previously retrieved into the email inbox for the given account.
- `MarkAsRead(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; ExternalId: Text)`: Marks the specified email as read.
- `GetEmailCategories(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; var EmailCategories: Record "Email Categories" temporary)`: Gets email categories from the specified email account.
- `CreateEmailCategory(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; CategoryDisplayName: Text): Text`: Creates a new email category in the specified email account.
- `CreateEmailCategory(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; CategoryDisplayName: Text; CategoryColor: Text): Text`: Creates a new email category with a specified color in the specified email account.
- `ApplyEmailCategory(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; ExternalId: Text; CategoryDisplayName: Text)`: Applies email categories to an email message.
- `ApplyEmailCategory(EmailAccountId: Guid; EmailConnector: Enum "Email Connector"; ExternalId: Text; Categories: List of [Text])`: Applies email categories to an email message.
- `OpenInEditor(EmailMessage: Codeunit "Email Message")`: Opens an email message in "Email Editor" page.
- `OpenInEditor(EmailMessage: Codeunit "Email Message"; EmailScenario: Enum "Email Scenario")`: Opens an email message in "Email Editor" page.
- `OpenInEditor(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary)`: Opens an email message in "Email Editor" page.
- `OpenInEditor(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector")`: Opens an email message in "Email Editor" page.
- `OpenInEditorModally(EmailMessage: Codeunit "Email Message"): Enum "Email Action"`: Opens an email message in "Email Editor" page modally.
- `OpenInEditorModally(EmailMessage: Codeunit "Email Message"; EmailScenario: Enum "Email Scenario"): Enum "Email Action"`: Opens an email message in "Email Editor" page modally.
- `OpenInEditorModallyWithScenario(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary; Scenario: Enum "Email Scenario"): Enum "Email Action"`: Opens an email message in "Email Editor" page modally with scenario.
- `OpenInEditorModally(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary): Enum "Email Action"`: Opens an email message in "Email Editor" page modally.
- `OpenInEditorModally(EmailMessage: Codeunit "Email Message"; EmailAccountId: Guid; EmailConnector: Enum "Email Connector"): Enum "Email Action"`: Opens an email message in "Email Editor" page modally.
- `GetSentEmailsForRecord(TableId: Integer; SystemId: Guid; var ResultSentEmails: Record "Sent Email" temporary)`: Gets the sent emails related to a record.
- `GetSentEmailsForRecord(RecordVariant: Variant; var ResultSentEmails: Record "Sent Email" temporary)`: Gets the sent emails related to a record.
- `GetEmailOutboxForRecord(RecordVariant: Variant; var ResultEmailOutbox: Record "Email Outbox" temporary)`: Gets the outbox emails related to a record.
- `OpenSentEmails(TableId: Integer; SystemId: Guid)`: Open the sent emails page for a source record given by its table ID and system ID.
- `OpenSentEmails(RecordVariant: Variant)`: Open the sent emails page for a source record.
- `OpenSentEmails(TableId: Integer; SystemId: Guid; NewerThanDate: DateTime)`: Open the sent emails page for a source record given by its table ID and system ID.
- `GetOutboxEmailRecordStatus(MessageId: Guid): Enum "Email Status"`: Gets the outbox email status.
- `AddRelation(EmailMessage: Codeunit "Email Message"; TableId: Integer; SystemId: Guid; RelationType: Enum "Email Relation Type"; Origin: Enum "Email Relation Origin")`: Adds a relation between an email message and a record.
- `RemoveRelation(EmailMessage: Codeunit "Email Message"; TableId: Integer; SystemId: Guid): Boolean`: Removes a related record from an email message.
- `HasRelations(EmailMessage: Codeunit "Email Message"): Boolean`: Check if email has any related records linked.
- `AddDefaultAttachments(EmailMessage: Codeunit "Email Message"; EmailScenario: Enum "Email Scenario")`: Adds the default attachments of a scenario to the email message.

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 8900 "Email Impl"](../codeunit/8900.md) (25 calls: `AddDefaultAttachments → AddDefaultAttachments`, `AddRelation → AddRelation`, `ApplyEmailCategory → ApplyEmailCategory`, …)
- [Codeunit 8904 "Email Message"](../codeunit/8904.md) (1 call: `HasRelations → GetId`)

## Called by

- [Codeunit 8900 "Email Impl"](../codeunit/8900.md) (6 calls: `AddRelation → OnAfterAddRelation`, `BeforeReplyEmail → OnBeforeReplyEmail`, `BeforeSendEmail → OnBeforeSendEmail`, …)
- [Codeunit 9520 "Mail Management"](../codeunit/9520.md) (5 calls: `SendViaEmailModule → AddDefaultAttachments`, `SendViaEmailModule → AddRelation`, `SendViaEmailModule → Enqueue`, …)
- [Codeunit 8361 "Financial Report Export Job"](../codeunit/8361.md) (4 calls: `ExportPackageSchedule → AddRelation`, `ExportPackageSchedule → Send`, `ExportSchedule → AddRelation`, …)
- [Codeunit 8906 "Email Editor"](../codeunit/8906.md) (4 calls: `AddRelatedRecordsFromEmailAddress → AddRelation`, `AddRelatedRecordsFromEmailAddress → HasRelations`, `AttachFromRelatedRecords → OnGetAttachment`, …)
- [Codeunit 4582 "SOA Retrieve Emails"](../codeunit/4582.md) (3 calls: `AddEmailInboxToSOAEmails → ApplyEmailCategory`, `AddEmailInboxToSOAEmails → MarkAsRead`, `RetrieveEmails → RetrieveEmails`)
- [Codeunit 4397 "SOA Test Setup"](../codeunit/4397.md) (2 calls: `EmailConnectionTest → RetrieveEmails`, `EmailCountTest → RetrieveEmails`)
- [Codeunit 4419 "SOA Send Reply"](../codeunit/4419.md) (2 calls: `OnRun → Reply`, `OnRun → ReplyAll`)
- [Codeunit 6940 "EA Retrieve Emails"](../codeunit/6940.md) (2 calls: `AddEmailInboxToEAEmails → MarkAsRead`, `RetrieveEmails → RetrieveEmails`)
- [Codeunit 8887 "Email Test Mail"](../codeunit/8887.md) (2 calls: `OnRun → OnGetBodyForTestEmail`, `OnRun → Send`)
- [Codeunit 8888 "Email Dispatcher"](../codeunit/8888.md) (2 calls: `SendEmail → OnAfterEmailSendFailed`, `SendEmail → OnAfterEmailSent`)
- [Codeunit 8907 "Email Viewer"](../codeunit/8907.md) (2 calls: `EditAndSend → OpenInEditor`, `Resend → Enqueue`)
- [Codeunit 1368 "Monitored Field Notification"](../codeunit/1368.md) (1 call: `SendEmail → Enqueue`)
- [Codeunit 3309 "PA Demo Guide"](../codeunit/3309.md) (1 call: `SendDemoEmail → Send`)
- [Codeunit 3310 "PA Validate Setup"](../codeunit/3310.md) (1 call: `OnRun → RetrieveEmails`)
- [Codeunit 4509 "Email - Outlook API Helper"](../codeunit/4509.md) (1 call: `CreateEmailInboxFromJsonObject → FindRetrievedEmail`)
- [Codeunit 6938 "EA Agent Dispatcher"](../codeunit/6938.md) (1 call: `SendEmail → Send`)
- [Codeunit 6942 "EA Mailbox Access"](../codeunit/6942.md) (1 call: `AccessMailbox → RetrieveEmails`)
- [Codeunit 8897 "Email Error Handler"](../codeunit/8897.md) (1 call: `OnRun → OnAfterEmailSendFailed`)
- [Codeunit 8902 "Email Scenario Attach Impl."](../codeunit/8902.md) (1 call: `GetEmailAttachmentsByEmailScenarios → OnBeforeGetEmailAttachmentsByEmailScenarios`)
- [Page 4400 "SOA Setup"](../page/4400.md) (1 call: `SetDefaultInboxFolder → GetMailFolders`)
- [Page 4444 "Email Account Folders"](../page/4444.md) (1 call: `OnOpenPage → GetMailFolders`)
- [Page 9033 "Invite External Accountant"](../page/9033.md) (1 call: `SendInvitationEmail → Send`)

## Recent changes

- 2026-09-21 [#11612 Multiple runs of email retrieval on the same emails don't persist again](../../changes/bcapps/11612.md) (main, BC30, fix)
- 2026-07-20 [#8771 Add OnBeforeFilterRemovedSourceRecords integration event in Email Impl](../../changes/bcapps/8771.md) (main, BC30, feature)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-29

## Deprecations

- procedure EnqueueReply: Pending 26.0 (#if not CLEAN26), "Replaced by EnqueueReply without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter."
- procedure EnqueueReplyAll: Pending 26.0 (#if not CLEAN26), "Replaced by EnqueueReplyAll without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter."
- procedure Reply: Pending 26.0 (#if not CLEAN26), "Replaced by Reply without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter."
- procedure ReplyAll: Pending 26.0 (#if not CLEAN26), "Replaced by ReplyAll without the ExternalId parameter. ExternalId is not used and is contained in the EmailMessage parameter."
- procedure RetrieveEmails: Pending 26.0 (#if not CLEAN26), "Replaced by RetrieveEmails with an additional Filters parameter of type Record "Email Retrieval Filters"."

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "Email")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
