---
id: object/codeunit/9520
type: object
title: Codeunit 9520 "Mail Management"
summary: Codeunit 9520 "Mail Management" in Base Application (System.Email). 23 public procedures, 25 events, 2 event subscribers. Present since at least BC23, still in BC30, changed in BC24, BC27.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "27"
  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: bc816bba963c71a1d1b5f97ecf928661680178d32a6d5a61251c77036f7e9f31
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Modules/System/Email/MailManagement.Codeunit.al
    title: src/Layers/W1/BaseApp/Modules/System/Email/MailManagement.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
object_type: codeunit
object_id: 9520
name: Mail Management
namespace: System.Email
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "27"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 56
  events: 25
  subscribers: 2
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 3
  calls: 9
  called_by: 60
  implements: 0
---

# Codeunit 9520 "Mail Management"

> Codeunit 9520 "Mail Management" in Base Application (System.Email). 23 public procedures, 25 events, 2 event subscribers. Present since at least BC23, still in BC30, changed in BC24, BC27.

Base Application · System.Email · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Modules/System/Email/MailManagement.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Permissions | TableData "Email Attachments" = rimd |

## Events published

- `OnSetIsHandlingGetEmailBodyCustomer(var Result: Boolean)` (integration)
  - subscribers: [Codeunit 9520 "Mail Management"](../codeunit/9520.md) HandleOnOnSetIsHandlingGetEmailBodyCustomer
- `OnSetIsHandlingGetEmailBodyVendor(var Result: Boolean)` (integration)
  - subscribers: [Codeunit 9520 "Mail Management"](../codeunit/9520.md) HandleOnSetIsHandlingGetEmailBodyVendor
- `OnBeforeCheckValidEmailAddresses(Recipients: Text; var IsHandled: Boolean)` (integration)
- `OnBeforeCheckValidEmailAddr(EmailAddress: Text; var IsHandled: Boolean)` (integration)
- `OnBeforeDoSending(var CancelSending: Boolean)` (integration)
- `OnBeforeIsEnabled(OutlookSupported: Boolean; var Result: Boolean; var IsHandled: Boolean)` (integration)
- `OnBeforeDownloadPdfAttachment(var TempEmailItem: Record "Email Item" temporary; var IsHandled: Boolean)` (integration)
  - subscribers: [Codeunit 1630 "Office Management"](../codeunit/1630.md) OnBeforeDownloadPdfAttachment
- `OnBeforeQualifyFromAddress(var TempEmailItem: Record "Email Item" temporary)` (integration)
- `OnBeforeValidateEmailAddressField(var EmailAddress: Text; var IsHandled: Boolean)` (integration)
- `OnBeforeSendMailOnWinClient(var TempEmailItem: Record "Email Item" temporary)` (integration, obsolete 27.0)
- `OnAfterDeleteTempAttachments(var EmailItem: Record "Email Item")` (integration, obsolete 27.0)
- `OnAfterGetSenderEmailAddress(var EmailItem: Record "Email Item")` (integration)
- `OnAfterIsBackground(var Result: Boolean)` (integration)
- `OnAfterGetAttachmentName(AttachmentNames: List of [Text]; Index: Integer; var AttachmentName: Text[250]; var TempEmailItem: Record "Email Item" temporary)` (integration)
- `OnAfterSendMailOrDownload(var TempEmailItem: Record "Email Item" temporary; var MailSent: Boolean)` (integration)
- `OnBeforeImageBase64ToUrl(var BodyText: Text; var SearchText: Text; var Regex: DotNet Regex; var MemoryStream: DotNet MemoryStream; var MediaId: Guid; var Base64: Text; var Convert: DotNet Convert; var IsHandled: Boolean)` (integration)
- `OnQualifyFromAddressOnAfterGetEmailAccount(var TempEmailItem: Record "Email Item" temporary; EmailScenario: Enum "Email Scenario"; var TempEmailAccount: Record "Email Account" temporary)` (integration)
- `OnSendOnBeforeQualifyFromAddress(var TempEmailItem: Record "Email Item" temporary; EmailScenario: Enum "Email Scenario")` (integration)
- `OnSendMailOrDownloadOnBeforeMailManagementIsSent(var MailManagement: Codeunit "Mail Management"; TempEmailItem: Record "Email Item" temporary)` (integration)
- `OnSendViaEmailModuleOnAfterAddAttachments(var Message: Codeunit "Email Message"; var TempEmailItem: Record "Email Item" temporary)` (integration)
- `OnSendViaEmailModuleOnAfterCreateMessage(var Message: Codeunit "Email Message"; var TempEmailItem: Record "Email Item" temporary)` (integration)
- `OnSendViaEmailModuleOnAfterEmailSend(var Message: Codeunit "Email Message"; var TempEmailItem: Record "Email Item" temporary; var MailSent: Boolean; var Cancelled: Boolean; var HideEmailSendingError: Boolean)` (integration)
- `OnBeforeSendViaEmailModule(var TempEmailItem: Record "Email Item" temporary; EmailScenario: Enum "Email Scenario"; var TempEmailAccount: Record "Email Account" temporary; HideMailDialog: Boolean; var IsHandled: Boolean; var Result: Boolean)` (integration)
- `OnAfterDownloadPDFAttachment()` (integration)
- `OnSendViaEmailModuleOnBeforeOpenInEditorModally(EmailScenario: Enum "Email Scenario"; var TempEmailAccount: Record "Email Account" temporary; var Message: Codeunit "Email Message"; var HideMailDialog: Boolean)` (integration)

## Event subscriptions

- HandleOnOnSetIsHandlingGetEmailBodyCustomer subscribes to Codeunit "Mail Management" OnSetIsHandlingGetEmailBodyCustomer
- HandleOnSetIsHandlingGetEmailBodyVendor subscribes to Codeunit "Mail Management" OnSetIsHandlingGetEmailBodyVendor

## Procedures

- `AddSource(TableId: Integer; SystemId: Guid)`
- `AddSendTo(EmailAddresses: Text)`
- `RecipientStringToList(DelimitedRecipients: Text; var Recipients: List of [Text])` (internal)
- `InitializeFrom(NewHideMailDialog: Boolean; NewHideEmailSendingError: Boolean)`
- `SetHideMailDialog(NewHideMailDialog: Boolean)`
- `SetHideEmailSendingError(NewHideEmailSendingError: Boolean)`
- `CheckValidEmailAddresses(Recipients: Text)`
- `CheckValidEmailAddress(EmailAddress: Text)`
- `ValidateEmailAddressField(var EmailAddress: Text)`
- `IsEnabled(): Boolean`
- `IsCancelled(): Boolean`
- `IsSent(): Boolean`
- `Send(var ParmEmailItem: Record "Email Item"; EmailScenario: Enum "Email Scenario"): Boolean`
- `Send(var ParmEmailItem: Record "Email Item"; EmailScenario: Enum "Email Scenario"; Enqueue: Boolean): Boolean`
- `SendMailOrDownload(var TempEmailItem: Record "Email Item" temporary; HideMailDialog: Boolean; EmailScenario: Enum "Email Scenario")`
- `SendMailOrDownload(var TempEmailItem: Record "Email Item" temporary; HideMailDialog: Boolean; EmailScenario: Enum "Email Scenario"; Enqueue: Boolean)`
- `DownloadPdfAttachment(var TempEmailItem: Record "Email Item" temporary)`
- `ImageBase64ToUrl(BodyText: Text): Text`
- `TryGetSenderEmailAddress(var FromAddress: Text[250])`
- `GetSenderEmailAddress(EmailScenario: Enum "Email Scenario"): Text[250]`
- `IsHandlingGetEmailBody(): Boolean`
- `IsHandlingGetEmailBodyCustomer(): Boolean`
- `IsHandlingGetEmailBodyVendor(): Boolean`

Plus 6 local procedures.

## Triggers

OnRun

## 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 8901 "Email"](../codeunit/8901.md) (5 calls: `SendViaEmailModule → AddDefaultAttachments`, `SendViaEmailModule → AddRelation`, `SendViaEmailModule → Enqueue`, …)
- [Codeunit 4102 "Temp Blob List"](../codeunit/4102.md) (4 calls: `DownloadPdfAttachment → (object)`, `DownloadPdfAttachment → Get`, `SendViaEmailModule → (object)`, …)
- [Codeunit 425 "Data Compression"](../codeunit/425.md) (4 calls: `DownloadPdfAttachment → AddEntry`, `DownloadPdfAttachment → CloseZipArchive`, `DownloadPdfAttachment → CreateZipArchive`, …)
- [Codeunit 4100 "Temp Blob"](../codeunit/4100.md) (3 calls: `DownloadPdfAttachment → CreateInStream`, `DownloadPdfAttachment → CreateOutStream`, `SendViaEmailModule → CreateInStream`)
- [Codeunit 8904 "Email Message"](../codeunit/8904.md) (3 calls: `SendViaEmailModule → AddAttachment`, `SendViaEmailModule → Create`, `SendViaEmailModule → GetId`)
- [Codeunit 8894 "Email Account"](../codeunit/8894.md) (2 calls: `CheckValidEmailAddress → ValidateEmailAddress`, `IsEnabled → IsAnyAccountRegistered`)
- [Codeunit 28 "Error Message Management"](../codeunit/28.md) (1 call: `SendViaEmailModule → LogSimpleErrorMessage`)
- [Codeunit 4030 "Client Type Management"](../codeunit/4030.md) (1 call: `IsBackground → GetCurrentClientType`)
- [Codeunit 8893 "Email Scenario"](../codeunit/8893.md) (1 call: `QualifyFromAddress → GetEmailAccount`)

## Called by

- [Codeunit 5916 "ServMailManagement"](../codeunit/5916.md) (4 calls: `OnRun → IsEnabled`, `OnRun → Send`, `OnRun → SetHideEmailSendingError`, …)
- [Codeunit 104058 "Upgrade User Setup"](../codeunit/104058.md) (1 call: `SetEmailOnRecord → CheckValidEmailAddress`)
- [Codeunit 1509 "Notification Entry Dispatcher"](../codeunit/1509.md) (1 call: `CreateMailAndDispatch → IsEnabled`)
- [Codeunit 1687 "Email Logging Message"](../codeunit/1687.md) (1 call: `GetEmailAddressProperty → ValidateEmailAddressField`)
- [Codeunit 1890 "Reminder Communication"](../codeunit/1890.md) (1 call: `PopulateEmailText → IsHandlingGetEmailBody`)
- [Codeunit 47021 "SL Vendor Migrator"](../codeunit/47021.md) (1 call: `CreateOrUpdateOrderAddress → ValidateEmailAddressField`)
- [Codeunit 6702 "O365 Contact Sync. Helper"](../codeunit/6702.md) (1 call: `TransferExchangeContactToNavContactNoValidate → CheckValidEmailAddress`)
- [Report 116 "Statement"](../report/116.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 117 "Reminder"](../report/117.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 118 "Finance Charge Memo"](../report/118.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1303 "Standard Sales - Draft Invoice"](../report/1303.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1304 "Standard Sales - Quote"](../report/1304.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1305 "Standard Sales - Order Conf."](../report/1305.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1306 "Standard Sales - Invoice"](../report/1306.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1307 "Standard Sales - Credit Memo"](../report/1307.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1308 "Standard Sales - Shipment"](../report/1308.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1309 "Standard Sales - Return Rcpt."](../report/1309.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1316 "Standard Statement"](../report/1316.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 1322 "Standard Purchase - Order"](../report/1322.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 208 "Sales - Shipment"](../report/208.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 210 "Blanket Sales Order"](../report/210.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 215 "Archived Sales Quote"](../report/215.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 216 "Archived Sales Order"](../report/216.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 404 "Purchase - Quote"](../report/404.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 405 "Order"](../report/405.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 406 "Purchase - Invoice"](../report/406.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 407 "Purchase - Credit Memo"](../report/407.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 408 "Purchase - Receipt"](../report/408.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 410 "Blanket Purchase Order"](../report/410.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 413 "Self Billing Invoice"](../report/413.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 415 "Archived Purchase Quote"](../report/415.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 416 "Archived Purchase Order"](../report/416.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 417 "Arch.Purch. Return Order"](../report/417.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 418 "Arch. Sales Return Order"](../report/418.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5055 "Contact - Cover Sheet"](../report/5055.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5064 "Segment - Cover Sheet"](../report/5064.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5085 "Contact Cover Sheet"](../report/5085.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5174 "Archived Blanket Purch. Order"](../report/5174.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5176 "Archived Blanket Sales Order"](../report/5176.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5751 "Put-away List"](../report/5751.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5752 "Picking List"](../report/5752.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5900 "Service Order"](../report/5900.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5902 "Service Quote"](../report/5902.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5911 "Service - Invoice"](../report/5911.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5912 "Service - Credit Memo"](../report/5912.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5913 "Service - Shipment"](../report/5913.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5970 "Service Contract"](../report/5970.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 5972 "Service Contract Quote"](../report/5972.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 6222 "EUDR Sales Invoice"](../report/6222.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- [Report 6631 "Return Order Confirmation"](../report/6631.md) (1 call: `IsReportInPreviewMode → IsHandlingGetEmailBody`)
- and 10 more: data/code/graph/29/calls.json

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24, BC27

## Deprecations

- procedure OnAfterDeleteTempAttachments: Pending 27.0 (#if not CLEAN27), "This event is never raised."
- procedure OnBeforeSendMailOnWinClient: Pending 27.0 (#if not CLEAN27), "This event is never raised."

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: "Mail Management")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
