Contributed by CURABIS ApS, generalized from patterns observed across real AppSource/PTE development. Each article follows the knowledge file format (frontmatter, Description/Best Practice/Anti Pattern, sibling .good.al/.bad.al samples).
1.4 KiB
| bc-version | domain | keywords | technologies | countries | application-area | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
breaking-changes |
|
|
|
|
Send email through the Email module, not Codeunit Mail (397)
Contributions welcome — open a PR to refine or extend this article.
Description
Older AL code sends email by calling Codeunit Mail (397). Business Central's current extensibility model is a different, richer object set — Codeunit Email, table Email Message, enum "Email Scenario", and the Email Account/Email Connector interface (Microsoft 365, Current User, SMTP, or a custom connector). New code built on Codeunit Mail inherits its SMTP-era, single-connector assumptions and leaves no Sent/Outbox trail behind.
Best Practice
Build on Codeunit Email and table Email Message. Route the message through an Email Scenario so different document types can use different accounts without the calling code needing to know which account that is, and get a tracked Sent/Outbox/Draft record for free.
See sample: prefer-email-module.good.al.
Anti Pattern
Calling Codeunit Mail's CreateMessage/Send/GetErrorDesc. It still runs, but it is hard-coupled to whatever SMTP setup exists, and leaves no queryable record of what was sent.
See sample: prefer-email-module.bad.al.