Skip to content

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Sep 16, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #20045

Description

See the linked issue for a description.

Testing this PR

You'll need to be able to receive notification emails from Umbraco. An easy way to do that is to configure the SMTP options to use the SpecifiedPickupDirectory in appsettings.json:

{
  "Umbraco": {
    "CMS": {
      "Global": {
        "Smtp": {
          "From": "your@email.here",
          "DeliveryMethod": "SpecifiedPickupDirectory",
          "PickupDirectoryLocation": "C:\\Temp\\MailDrop"
        }
      },
      ....

You'll also need to enable segments for document types. This code snippet should do the trick in V13:

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;

namespace Umbraco.Cms.Web.UI.Custom;

public class ServerVariablesParsingNotificationHandler : INotificationHandler<ServerVariablesParsingNotification>
{
    public void Handle(ServerVariablesParsingNotification notification)
    {
        if (!notification.ServerVariables.TryGetValue("umbracoSettings", out var umbracoSettingsObject)
            || umbracoSettingsObject is not IDictionary<string, object> umbracoSettings)
        {
            umbracoSettings = new Dictionary<string, object>();
            notification.ServerVariables.Add("umbracoSettings", umbracoSettings);
        }

        umbracoSettings["showAllowSegmentationForDocumentTypes"] = true;
    }
}

public class EnableSegmentsComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
        => builder.AddNotificationHandler<ServerVariablesParsingNotification, ServerVariablesParsingNotificationHandler>();
}

With all that in place, create a new doctype with "Allow segmentation" enabled:

image

Note that you don't actually need any segmented properties to test this PR 😄

Now create a document of the segmented doctype, and sign up for any notification for that document. I've used the "Update" notification for testing, because it's easy to trigger.

image

When this is in place, trigger the notification (e.g. save the document again if you're using the "Update" notifcation).

Without this PR, the NotSupportedException from NotificationService bubbles all the way into the UI:

image

With this PR, the notification email should be sent (or generated on disk, if you configured SpecifiedPickupDirectory).

Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests out as described. I've verified with an invariant, vary by culture and vary by segments configured document type and see the emails coming through with expected content in all cases.

@AndyButland AndyButland merged commit 301be35 into v13/dev Sep 17, 2025
20 checks passed
@AndyButland AndyButland deleted the v13/bugfix/notification-service-segmented-content branch September 17, 2025 04:51
@AndyButland
Copy link
Contributor

🍒 picked for 16.3 in 546849d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants