bcquality/microsoft/knowledge/breaking-changes/prefer-email-module.md
Michael Dieringer cc7c1f2ee0 Address Jesper Schulz-Wedde's review on PR #156
- Rename 3 articles so their .good.al/.bad.al companion stems match
  (do-not-change-primary-key, testfield-required-setup-field,
  al-identifiers-english), fixing the R14 orphan-sample errors.
- do-not-change-primary-key.good.al: include Flow in the new table's
  own primary key so it actually models the discriminating dimension.
- al-build-output-must-not-pollute-project-root.md: drop the
  unsubstantiated AL0197 causal claim and the non-existent
  al.outputPath setting; reframe as build-artifact hygiene sourced
  from ALTool --outfolder / al_build outputPath.
- prefer-email-module.md: Email Message is Codeunit 8904, not a table;
  distinguish it from the underlying Sent/Outbox/Draft storage.
- file-datatype-saas.md: File.Open/Create/Read/Write fails to compile
  against a Cloud-scoped project, it does not compile and silently
  fail at runtime.
- namespace-must-be-verified-from-source.md: narrow to "resolve from
  the referenced object's source or symbols," since source-file line
  one is not the only authoritative source (symbol packages, comments
  before the namespace line).
- test-data-must-be-random-and-complete.md: drop "assume an empty
  database" and "collision-free" absolutes; reframe around
  independence from unrelated business records and reserving explicit
  values for scenario-defining inputs.
- binary-choice-must-be-boolean.md: scope to genuine true/false
  semantics, not mechanical two-member-enum-to-boolean conversion.
- document-report-word-layout.md: scope down to a sourced Microsoft
  Learn recommendation instead of an unconditional performance
  guarantee; cite the three Learn pages.
- Wire the new articles into their review skills' candidate-selection
  signals (file-datatype-saas, prefer-email-module,
  namespace-must-be-verified-from-source, var-parameters-require-an-
  addressable-variable) so they can actually enter a worklist.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-21 22:25:26 +02:00

1.6 KiB

bc-version domain keywords technologies countries application-area
all
breaking-changes
email
codeunit-mail
email-message
email-scenario
email-account
smtp
sending-email
al
w1
all

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, Codeunit "Email Message", enum "Email Scenario", and the Email Account/Email Connector interface (Microsoft 365, Current User, SMTP, or a custom connector). Codeunit "Email Message" is the in-memory object you build the message on; it is not itself the persisted Sent/Outbox/Draft record — that storage is managed separately once the message is queued or sent. 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 Codeunit "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.