{"title":"Codeunit 5052 AttachmentManagement, extension points 29","url":"https://jonas-paprotka.de/ref/codeunit/5052-attachmentmanagement/points/","author":"JOP-AL","license":"Metadata from Microsoft's symbol packages. AL source MIT, Copyright (c) Microsoft Corporation. Selection and wording © 2026 JOP-AL. https://jonas-paprotka.de/licenses/","subject":"Microsoft Dynamics 365 Business Central","checked":"2026-11-20","changed":"2026-10-05","object":{"type":"codeunit","id":5052,"name":"AttachmentManagement","app":"Base Application","url":"https://jonas-paprotka.de/ref/codeunit/5052-attachmentmanagement/"},"major":29,"source":{"url":"https://jonas-paprotka.de/ref/codeunit/5052-attachmentmanagement/source/","path":"src/Layers/W1/BaseApp/CRM/Interaction/AttachmentManagement.Codeunit.al","commit":"4303e5e584d3aa5d9e98cbc615525a5396ad6ed7","lines":"a line is <source url>#L<line>"},"steps":{"event":"[line, \"event\", name, handled]: raises an event of this object; handled 1 when it has an IsHandled parameter","call":"[line, \"call\", name, arguments]: calls a procedure of this object","ext":"[line, \"ext\", type, id, name, arguments]: calls a procedure of another object, through a variable declared with that type","write":"[line, \"write\", table id, method, 1 when called with true]: Insert, Modify, ModifyAll, Delete, DeleteAll or Rename","validate":"[line, \"validate\", table id, field name]","run":"[line, \"run\", type, id]: Codeunit.Run, Page.Run, Report.Run and their kin"},"objects":{"table:5062":{"name":"Attachment","url":"https://jonas-paprotka.de/ref/table/5062-attachment/"},"codeunit:5069":{"name":"Word Template Interactions","url":"https://jonas-paprotka.de/ref/codeunit/5069-word-template-interactions/"},"codeunit:419":{"name":"File Management","url":"https://jonas-paprotka.de/ref/codeunit/419-file-management/"},"table:9651":{"name":"Report Layout Selection","url":"https://jonas-paprotka.de/ref/table/9651-report-layout-selection/"},"report:5084":{"name":"Email Merge","url":"https://jonas-paprotka.de/ref/report/5084-email-merge/"},"codeunit:6300":{"name":"Azure AD Mgt.","url":"https://jonas-paprotka.de/ref/codeunit/6300-azure-ad-mgt/"},"codeunit:5321":{"name":"Exchange Web Services Server","url":"https://jonas-paprotka.de/ref/codeunit/5321-exchange-web-services-server/"},"codeunit:4100":{"name":"Temp Blob","url":"https://jonas-paprotka.de/ref/codeunit/4100-temp-blob/"},"codeunit:260":{"name":"Document-Mailing","url":"https://jonas-paprotka.de/ref/codeunit/260-document-mailing/"},"table:5065":{"name":"Interaction Log Entry","url":"https://jonas-paprotka.de/ref/table/5065-interaction-log-entry/"},"table:5074":{"name":"Delivery Sorter","url":"https://jonas-paprotka.de/ref/table/5074-delivery-sorter/"}},"procs":[{"name":"InsertAttachment","line":35,"kind":"procedure","params":1,"steps":[[48,"write",5062,"Insert",1],[51,"event","OnInsertAttachmentOnAfterAttachmentInserted",1],[57,"call","TransferAttachment",2]]},{"name":"Send","line":63,"kind":"procedure","params":1,"steps":[[72,"event","OnBeforeSend",1],[75,"call","ProcessDeliverySorter",4],[78,"ext","codeunit",5069,"Merge",1],[81,"call","DeliverHTMLEmail",2],[84,"call","DeliverEmailWithAttachment",2],[86,"event","OnAfterSend",0]]},{"name":"SendUsingExchange","line":92,"kind":"procedure","params":1,"steps":[[101,"call","ProcessDeliverySorter",4],[104,"ext","codeunit",5069,"Merge",1],[106,"call","InitializeExchange",1],[108,"call","DeliverHTMLEmailViaExchange",3],[111,"call","DeliverEmailWithAttachmentViaExchange",3]]},{"name":"TransferAttachment","line":114,"kind":"procedure","access":"local","params":2,"steps":[[124,"ext","table",5062,"ConstDiskFileName",0],[125,"ext","table",5062,"ExportAttachmentToServerFile",1],[130,"write",5062,"Modify"],[140,"write",5062,"Modify"],[141,"ext","table",5062,"ConstDiskFileName",0],[141,"ext","table",5062,"ConstDiskFileName",0],[148,"ext","table",5062,"ImportAttachmentFromServerFile",3],[148,"ext","table",5062,"ConstDiskFileName",0],[151,"write",5062,"Modify"]]},{"name":"InteractionEMail","line":155,"kind":"procedure","params":1,"steps":[[161,"event","OnBeforeInteractionEMail",1]]},{"name":"GenerateHTMLContent","line":178,"kind":"procedure","params":2,"steps":[[180,"ext","table",5062,"IsHTML",0],[183,"ext","table",5062,"IsHTMLReady",0],[186,"call","GenerateHTMLReadyAttachmentFromCustomLayout",2]]},{"name":"LoadHTMLContent","line":190,"kind":"procedure","params":2,"steps":[[192,"ext","table",5062,"IsHTML",0],[195,"ext","table",5062,"IsHTMLReady",0],[196,"ext","table",5062,"Read",0],[198,"call","LoadHTMLContentFromCustomLayoutAttachment",2]]},{"name":"LoadHTMLContentFromCustomLayoutAttachment","line":201,"kind":"procedure","access":"local","params":2,"steps":[[207,"call","GenerateHTMLReadyContentFromCustomLayoutAttachment",2],[212,"ext","table",5062,"ImportAttachmentFromServerFile",3],[214,"write",5062,"Insert"],[215,"ext","table",5062,"Read",0],[216,"ext","table",5062,"RemoveAttachment",1]]},{"name":"GenerateHTMLReadyAttachmentFromCustomLayout","line":219,"kind":"procedure","access":"local","params":2,"steps":[[223,"call","GenerateHTMLReadyContentFromCustomLayoutAttachment",2],[227,"write",5062,"Delete"],[229,"ext","table",5062,"ImportAttachmentFromServerFile",3],[231,"write",5062,"Insert"]]},{"name":"GenerateHTMLReadyContentFromCustomLayoutAttachment","line":236,"kind":"procedure","access":"local","params":2,"steps":[[246,"ext","codeunit",419,"ServerTempFileName",0],[250,"ext","table",5062,"ReadHTMLCustomLayoutAttachment",3],[252,"ext","table",9651,"SetTempLayoutSelectedName",1],[254,"ext","table",9651,"SetTempLayoutSelected",1],[255,"ext","report",5084,"InitializeRequest",2],[256,"ext","report",5084,"SaveAsHtml",1],[257,"ext","table",9651,"ClearTempLayoutSelected",0]]},{"name":"InitializeExchange","line":260,"kind":"procedure","access":"local","params":1,"steps":[[266,"call","InitializeExchangeWithToken",2]]},{"name":"InitializeExchangeWithToken","line":271,"kind":"procedure","access":"local","params":2,"steps":[[277,"ext","codeunit",6300,"GetAccessTokenAsSecretText",3],[277,"ext","codeunit",6300,"GetO365Resource",0],[277,"ext","codeunit",6300,"GetO365ResourceName",0],[280,"ext","codeunit",5321,"InitializeWithOAuthToken",2],[280,"ext","codeunit",5321,"GetEndpoint",0],[286,"ext","codeunit",5321,"InitializeWithCertificate",5],[291,"ext","codeunit",5321,"SetImpersonatedIdentity",1]]},{"name":"DeliverHTMLEmail","line":302,"kind":"procedure","access":"local","params":2,"steps":[[308,"event","OnBeforeDeliverHTMLEmail",1],[317,"call","GetAttachment",3],[319,"ext","table",5062,"ExportAttachmentToTempBlob",1],[321,"event","OnDeliverHTMLEmailOnBeforeSendEmail",0],[323,"event","OnDeliverHTMLEmailOnBeforeSendEmail",0],[326,"call","SendHTMLEmail",3],[328,"call","SetDeliveryState",2]]},{"name":"DeliverHTMLEmailViaExchange","line":332,"kind":"procedure","access":"local","params":3,"steps":[[343,"call","GetAttachment",3],[344,"ext","codeunit",419,"ServerTempFileName",0],[345,"ext","table",5062,"ExportAttachmentToServerFile",1],[348,"call","SendHTMLEmailViaExchange",4],[351,"ext","codeunit",419,"DeleteServerFile",1],[353,"call","SetDeliveryState",2]]},{"name":"DeliverEmailWithAttachment","line":357,"kind":"procedure","access":"local","params":2,"steps":[[364,"event","OnBeforeDeliverEmailWithAttachment",1],[372,"call","GetAttachment",3],[374,"ext","table",5062,"ExportAttachmentToTempBlob",1],[376,"call","PrepareDummyEmailBody",1],[378,"event","OnDeliverEmailWithAttachmentOnBeforeSendEmail",0],[380,"event","OnDeliverEmailWithAttachmentOnBeforeSendEmail",0],[382,"call","SendEmailWithAttachment",4],[384,"call","SetDeliveryState",2]]},{"name":"DeliverEmailWithAttachmentViaExchange","line":388,"kind":"procedure","access":"local","params":3,"steps":[[412,"call","PrepareServerAttachment",1],[417,"call","SendEmailWithAttachmentViaExchange",4],[420,"ext","codeunit",419,"DeleteServerFile",1],[422,"call","SetDeliveryState",2]]},{"name":"SendHTMLEmail","line":429,"kind":"procedure","access":"local","params":3,"steps":[[439,"ext","codeunit",4100,"CreateInStream",1],[451,"ext","codeunit",260,"EmailFile",10],[453,"call","InteractionEMail",1],[455,"call","SetDeliveryState",2]]},{"name":"SendHTMLEmailViaExchange","line":458,"kind":"procedure","access":"local","params":4,"steps":[[463,"ext","codeunit",5321,"SendEmailMessageWithAttachment",5],[464,"call","InteractionEMail",1],[465,"ext","table",5062,"Read",0],[465,"call","GetSenderSalesPersonEmail",1],[467,"call","SetDeliveryState",2]]},{"name":"SendEmailWithAttachment","line":470,"kind":"procedure","access":"local","params":4,"steps":[[479,"ext","codeunit",4100,"HasValue",0],[480,"ext","codeunit",4100,"CreateInStream",1],[492,"ext","codeunit",260,"EmailFile",10],[493,"call","GetAttachmentFileDefaultName",1],[494,"call","InteractionEMail",1],[496,"call","SetDeliveryState",2]]},{"name":"SendEmailWithAttachmentViaExchange","line":499,"kind":"procedure","access":"local","params":4,"steps":[[504,"ext","codeunit",5321,"SendEmailMessageWithAttachment",5],[505,"call","InteractionEMail",1],[506,"call","GetSenderSalesPersonEmail",1],[507,"call","SetDeliveryState",2]]},{"name":"PrepareServerAttachment","line":510,"kind":"procedure","access":"local","params":1,"steps":[[517,"call","GetAttachment",3],[518,"ext","codeunit",419,"ServerTempFileName",0],[519,"ext","table",5062,"ExportAttachmentToServerFile",1],[520,"ext","codeunit",419,"CombinePath",2],[521,"ext","codeunit",419,"GetDirectoryName",1],[522,"ext","codeunit",419,"CopyServerFile",3],[523,"ext","codeunit",419,"DeleteServerFile",1]]},{"name":"SetDeliveryState","line":527,"kind":"procedure","access":"local","params":2,"steps":[[529,"event","OnBeforeSetDeliveryState",0],[534,"event","OnSetDeliveryStateOnBeforeModifyInteractLogEntry",0],[535,"write",5065,"Modify"]]},{"name":"ProcessDeliverySorter","line":539,"kind":"procedure","access":"local","params":4,"steps":[[549,"event","OnBeforeProcessDeliverySorter",1],[572,"write",5074,"Insert"],[577,"event","OnProcessDeliverySorterHtml",0],[578,"write",5074,"Insert"],[580,"ext","codeunit",5069,"IsWordDocumentExtension",1],[583,"event","OnProcessDeliverySorterWord",0],[584,"write",5074,"Insert"],[588,"event","OnProcessDeliverySorterOther",0],[589,"write",5074,"Insert"]]},{"name":"PrepareDummyEmailBody","line":607,"kind":"procedure","access":"local","params":1,"steps":[[612,"ext","codeunit",4100,"CreateOutStream",1]]},{"name":"ConvertCorrespondenceType","line":624,"kind":"procedure","params":1,"steps":[[634,"event","OnConvertCorrespondenceTypeElse",1]]}]}