Dependencies: Update MailKit dependency and resolve nullability breaking changes (for Umbraco 13) - #23306
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request upgrades the MailKit dependency to remediate a vulnerability and updates Umbraco’s email-related call sites to compile cleanly against MailKit/MimeKit assemblies that now ship with nullable reference type annotations.
Changes:
- Bumped
MailKitpackage version from4.8.0to4.17.0. - Updated MIME/message construction to satisfy new nullability annotations (e.g.,
InternetAddress.TryParseout vars;MimeMessage.Subject/TextPart.Textassignments). - Added an SMTP host guard in
EmailSenderto fail earlier with a clearer configuration error.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Directory.Packages.props | Updates MailKit package version to 4.17.0. |
| src/Umbraco.Infrastructure/Extensions/EmailMessageExtensions.cs | Adjusts parsing and MIME message creation to align with new nullable annotations. |
| src/Umbraco.Infrastructure/Mail/EmailSender.cs | Adds configuration guard before SMTP connection. |
| src/Umbraco.Web.BackOffice/Controllers/UsersController.cs | Updates invite-email recipient mailbox construction for new nullability requirements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Zeegaan
left a comment
There was a problem hiding this comment.
Looks good, tests good 😁
I am a little concerned with packages compiled against earlier versions, but it should theoretically be fine if its just nullability right 🤔
|
I think so - as you say, the changes are only related to nullability. It's also quite unlikely that anyone would take a direct reference to this, given we have an email sending abstraction in core. We'll put this out as an RC with the usual two weeks too. |
Description
Updates the
MailKitdependency from 4.8.0 → 4.17.0 to remediate a known vulnerability in the previously referenced version. Although this is a minor version bump, it surfaced nullability-related compiler breaking changes, which are resolved here.Why a minor bump broke the build
This is not a runtime API change. Between 4.8.0 and 4.16.0, MailKit/MimeKit enabled
<Nullable>enable</Nullable>in their own build, so the shipped assemblies now carry nullable reference type annotations. 4.8.0 was nullable-oblivious (consumers got no warnings); 4.17.0 exposes real nullability, producing warnings — errors, under warnings-as-errors — at our call sites. Every change below is resolving a newly surfaced annotation, not a behavioural change in the library.Changes
Directory.Packages.props— MailKit4.8.0→4.17.0.EmailMessageExtensions.csInternetAddress.TryParsenow declares[NotNullWhen(true)] out InternetAddress?, so theoutlocals becomeInternetAddress?(the[NotNullWhen(true)]keeps their use inside the success branch warning-free).MimeMessage.SubjectandTextPart.Textrequire non-null values. SinceEmailMessage's constructor already enforces a non-null/non-emptySubjectandBody, these use the null-forgiving operator (mailMessage.Subject!/mailMessage.Body!) to make that invariant explicit. This keeps the original runtime behaviour and avoids masking an invalidEmailMessage— coalescing tostring.Emptywould silently hide such a violation.mailboxAddress.Name ?? string.Empty(dropped a redundant null-conditional on an already-proven-non-null value;InternetAddress.Nameis genuinely nullable, so the empty default is warranted here).EmailSender.cs—SmtpClient.ConnectAsync(host, …)requires a non-null host. Rather than silently pass an empty string (Hostis required config, and empty is never valid), added a guard that throws a clearInvalidOperationExceptionwhen no SMTP host is configured.UsersController.cs—MailboxAddress(string? name, string address)requires a non-null address. An invite email cannot be sent without a recipient, so rather than defaulting tostring.Emptythis now fails fast with a clearInvalidOperationExceptionwhen the recipient has no email address.Testing
To verify the full send path end-to-end I used this throwaway debug controller you can drop into
src/Umbraco.Web.UI/Controllers/.Log in, configure SMTP (e.g. using smtp4dev or a
SpecifiedPickupDirectoryto write.emlfiles to disk without a real server), then hit/umbraco/surface/debugemail/send?to=you@example.com.