In lesson 2.8.5 (“Sending mail, confirmed”) the Kladde built its first mail through Microsoft Graph: a GraphMailSender with an HttpClient, a
TokenCredential and the JSON by hand. That worked, but it was manual labor: putting the address together, fetching the token, setting the header, records for every
shape of the JSON. The Graph SDK takes exactly this work off your hands. This lesson switches sending over, adds what an office still needs around mail (attachments,
draft, reading a mailbox), and records what was right about the solution from K2 and therefore stays.
A word up front on the honesty of this course: No command and no code of this lesson was run against a Microsoft 365 tenant. Every statement about addresses, parameters, limits and response codes comes from Microsoft Learn, read for this lesson; answers of the service are described, not demonstrated. Where Learn leaves a question open, the text says “not read” or “open”. Every exercise that needs a tenant says so and has a part that runs without one.
| Part | What comes out of it |
|---|---|
| Decision | SDK instead of HttpClient: what stays (port, outbox, mapping of the responses), what goes away (token, address, JSON by hand) |
| Sending | sendMail with the SDK, saveToSentItems, header with the identifier, attachments, draft |
| Reading | reading a mailbox: folder, $filter, $orderby, $search, only the fields the Kladde needs |
| Permissions and data | Mail.Send and Mail.Read as application, restriction to one mailbox, data protection |
| Test | an interface of your own as the seam: the core never sees the GraphServiceClient |
Where the Kladde stands
From K2 you have, and this lesson takes it for granted:
- the port
IMailSenderwithOutgoingMail(Guid Id, string To, string Subject, string Text)and the resultDeliveryOutcome(Delivered,NotDelivered,Unclear), lesson 2.8.5; - the outbox and its dispatcher (lesson 2.8.4, “The outbox pattern”) with the rule “unclear is never repeated blindly” (lesson 2.8.3, “Retrying without sending twice”);
- a
TokenCredentialin the service collection: in K2 a client secret from the user secrets, with K3 (lesson 3.3.1, managed identity) without a secret; - the test pattern with a faked handler (lesson 2.8.1, “HttpClientFactory and an external API”).
A project Kladde.Graph is new. It depends on Kladde.Core and on the packages Microsoft.Graph and Azure.Identity; Kladde.Web references it. The
core (Kladde.Core) knows neither the SDK nor Graph; that is the rule of this whole module: The Kladde owns its interfaces, the SDK stands behind them.