---
id: object/codeunit/5052
type: object
title: Codeunit 5052 "AttachmentManagement"
summary: Codeunit 5052 "AttachmentManagement" in Base Application (Microsoft.CRM.Interaction). 7 public procedures, 15 events. Present since at least BC23, still in BC30, changed in BC26-27.
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: 2d675b0e1f1d91fa8b8d215e28eb47e0aea2eaf3ea9cfc3c161b95b3ac476201
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/CRM/Interaction/AttachmentManagement.Codeunit.al
    title: src/Layers/W1/BaseApp/CRM/Interaction/AttachmentManagement.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: 5052
name: AttachmentManagement
namespace: Microsoft.CRM.Interaction
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "26"
  - "27"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 43
  events: 15
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 6
  called_by: 9
  implements: 0
---

# Codeunit 5052 "AttachmentManagement"

> Codeunit 5052 "AttachmentManagement" in Base Application (Microsoft.CRM.Interaction). 7 public procedures, 15 events. Present since at least BC23, still in BC30, changed in BC26-27.

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

## Events published

- `OnAfterSend(var DeliverySorter: Record "Delivery Sorter"; var DeliverySorterHTML: Record "Delivery Sorter"; var DeliverySorterWord: Record "Delivery Sorter"; var DeliverySorterOther: Record "Delivery Sorter"; var InteractionLogEntry: Record "Interaction Log Entry")` (integration)
- `OnBeforeDeliverEmailWithAttachment(var DeliverySorter: Record "Delivery Sorter"; var IsHandled: Boolean; var InteractionLogEntry: Record "Interaction Log Entry")` (integration)
- `OnBeforeDeliverHTMLEmail(var DeliverySorter: Record "Delivery Sorter"; var InteractionLogEntry: Record "Interaction Log Entry"; var IsHandled: Boolean)` (integration)
- `OnBeforeInteractionEMail(var InteractionLogEntry: Record "Interaction Log Entry"; var EMailAddress: Text[80]; var IsHandled: Boolean)` (integration)
- `OnBeforeSend(var DeliverySorter: Record "Delivery Sorter"; var IsHandled: Boolean)` (integration)
- `OnBeforeSetDeliveryState(var InteractLogEntry: Record "Interaction Log Entry"; var IsSent: Boolean)` (integration)
- `OnDeliverEmailWithAttachmentOnBeforeSendEmail(var DeliverySorter: Record "Delivery Sorter"; var InteractionLogEntry: Record "Interaction Log Entry"; AttachmentFileFullName: Text; EmailBodyFilePath: Text)` (integration, obsolete 27.0)
- `OnDeliverHTMLEmailOnBeforeSendEmail(var DeliverySorter: Record "Delivery Sorter"; Attachment: Record Attachment; var InteractionLogEntry: Record "Interaction Log Entry"; EmailBodyFilePath: Text)` (integration, obsolete 27.0)
- `OnProcessDeliverySorterHtml(var DeliverySorter: Record "Delivery Sorter"; var TempDeliverySorter: Record "Delivery Sorter" temporary; Attachment: Record Attachment; I: Integer)` (integration)
- `OnProcessDeliverySorterOther(var DeliverySorter: Record "Delivery Sorter"; var TempDeliverySorter: Record "Delivery Sorter" temporary; Attachment: Record Attachment; I: Integer)` (integration)
- `OnProcessDeliverySorterWord(var DeliverySorter: Record "Delivery Sorter"; var TempDeliverySorter: Record "Delivery Sorter" temporary; Attachment: Record Attachment; I: Integer)` (integration)
- `OnConvertCorrespondenceTypeElse(CorrespondenceType: Option; var ReturnType: Enum "Correspondence Type"; var IsHandled: Boolean)` (integration)
- `OnSetDeliveryStateOnBeforeModifyInteractLogEntry(var InteractionLogEntry: Record "Interaction Log Entry"; IsSent: Boolean)` (integration)
- `OnBeforeProcessDeliverySorter(var DeliverySorter: Record "Delivery Sorter"; var TempDeliverySorterHtml: Record "Delivery Sorter" temporary; var TempDeliverySorterWord: Record "Delivery Sorter" temporary; var TempDeliverySorterOther: Record "Delivery Sorter" temporary; var IsHandled: Boolean)` (integration)
- `OnInsertAttachmentOnAfterAttachmentInserted(var Attachment: Record Attachment; AttachmentNo: Integer; var FromAttachment: Record Attachment; var IsHandled: Boolean)` (integration)

## Procedures

- `InsertAttachment(AttachmentNo: Integer): Integer`
- `Send(var DeliverySorter: Record "Delivery Sorter")`
- `SendUsingExchange(var DeliverySorter: Record "Delivery Sorter")`
- `InteractionEMail(var InteractionLogEntry: Record "Interaction Log Entry"): Text[80]`
- `GenerateHTMLContent(var Attachment: Record Attachment; SegmentLine: Record "Segment Line"): Boolean`
- `LoadHTMLContent(var Attachment: Record Attachment; SegmentLine: Record "Segment Line"): Text`
- `ConvertCorrespondenceType(CorrespondenceType: Option "Same as Entry","Hard Copy",Email): Enum "Correspondence Type"`

Plus 21 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 419 "File Management"](../codeunit/419.md) (9 calls: `DeliverEmailWithAttachmentViaExchange → DeleteServerFile`, `DeliverHTMLEmailViaExchange → DeleteServerFile`, `DeliverHTMLEmailViaExchange → ServerTempFileName`, …)
- [Codeunit 5321 "Exchange Web Services Server"](../codeunit/5321.md) (6 calls: `InitializeExchangeWithToken → GetEndpoint`, `InitializeExchangeWithToken → InitializeWithCertificate`, `InitializeExchangeWithToken → InitializeWithOAuthToken`, …)
- [Codeunit 4100 "Temp Blob"](../codeunit/4100.md) (4 calls: `PrepareDummyEmailBody → CreateOutStream`, `SendEmailWithAttachment → CreateInStream`, `SendEmailWithAttachment → HasValue`, …)
- [Codeunit 5069 "Word Template Interactions"](../codeunit/5069.md) (3 calls: `ProcessDeliverySorter → IsWordDocumentExtension`, `Send → Merge`, `SendUsingExchange → Merge`)
- [Codeunit 6300 "Azure AD Mgt."](../codeunit/6300.md) (3 calls: `InitializeExchangeWithToken → GetAccessTokenAsSecretText`, `InitializeExchangeWithToken → GetO365Resource`, `InitializeExchangeWithToken → GetO365ResourceName`)
- [Codeunit 260 "Document-Mailing"](../codeunit/260.md) (2 calls: `SendEmailWithAttachment → EmailFile`, `SendHTMLEmail → EmailFile`)

## Called by

- [Codeunit 5051 "SegManagement"](../codeunit/5051.md) (3 calls: `LogInteraction → Send`, `LogSegment → Send`, `UnwrapAttachmentCustomLayout → GenerateHTMLContent`)
- [Codeunit 5069 "Word Template Interactions"](../codeunit/5069.md) (2 calls: `GetMailToAddress → InteractionEMail`, `GetMergeSourceText → InteractionEMail`)
- [Table 5062 "Attachment"](../table/5062.md) (2 calls: `ImportAttachmentFromClientFile → InsertAttachment`, `PreviewHTMLContent → LoadHTMLContent`)
- [Table 5080 "To-do"](../table/5080.md) (2 calls: `CreateTaskInteractLanguages → InsertAttachment`, `UpdateInteractionTemplate → InsertAttachment`)
- [Table 5196 "To-do Interaction Language"](../table/5196.md) (2 calls: `CopyFromAttachment → InsertAttachment`, `ImportAttachment → InsertAttachment`)
- [Table 5076 "Segment Header"](../table/5076.md) (1 call: `CreateSegInteractions → InsertAttachment`)
- [Table 5077 "Segment Line"](../table/5077.md) (1 call: `FinishSegLineWizard → GenerateHTMLContent`)
- [Table 5103 "Interaction Tmpl. Language"](../table/5103.md) (1 call: `CopyFromAttachment → InsertAttachment`)
- [Table 5104 "Segment Interaction Language"](../table/5104.md) (1 call: `CopyFromAttachment → InsertAttachment`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC26-27

## Deprecations

- procedure OnDeliverEmailWithAttachmentOnBeforeSendEmail: Pending 27.0 (#if not CLEAN27), "Parameter AttachmentFileFullName and EmailBodyFilePath will be removed"
- procedure OnDeliverHTMLEmailOnBeforeSendEmail: Pending 27.0 (#if not CLEAN27), "Parameter EmailBodyFilePath will be removed"

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