Engineering · EXM · Sitecore
Email dispatch issue in Sitecore EXM
Recently we faced an interesting Sitecore EXM issue. We can create an email with a name up to 100 characters long. The default maxLength is 100. Once we create the email, we can find it in the content tree with the same name. During this process, there is no error.
However, when we sent the email, it moved to the in-progress / paused state, and in the EXM log we found the following errors:
ManagedPoolThread #12 10:49:22 INFO Dispatch Message (TEST DEO UGRAD - Officer Selection Board - OSB Sep 27 - 1 Oct 2021 - Test): Started
Message Id: {E14EC76B-8BE4-4156-8316-5333FB7FE1F7}
Message Path: /sitecore/content/Email/Messages/2021/09/16T061053/TEST DEO UGRAD - Officer Selection Board - OSB Sep 27 - 1 Oct 2021 - Test
Included Recipient Lists: Test Liston 02-06-2021
Excluded Recipient Lists:
ManagedPoolThread #12 10:49:22 ERROR Exception: Sitecore.Exceptions.InvalidItemNameException
Message: An item name lenght should be less or equal to 100.
Source: Sitecore.Kernel
at Sitecore.Data.Items.ItemUtil.AssertItemName(Item destinationItem, String name)
at Sitecore.Data.Items.Item.Add(String name, TemplateID templateID)
at Sitecore.Modules.EmailCampaign.Core.ItemUtilExt.AddSubItemFromTemplate(String name, String displayName, TemplateID templateId, Item parent)
at Sitecore.EmailCampaign.Cm.Pipelines.DispatchNewsletter.DeployAnalytics.AddCampaignItem(MessageItem message)
at Sitecore.EmailCampaign.Cm.Pipelines.DispatchNewsletter.DeployAnalytics.ProcessCampaign(MessageItem message)
at Sitecore.EmailCampaign.Cm.Pipelines.DispatchNewsletter.DeployAnalytics.Process(DispatchNewsletterArgs args)
The error message is surprising because it is coming from Sitecore Kernel and complaining that the item name is longer than 100 characters, while our email name is only 74. Another notable thing is that the error originated from “Sitecore.EmailCampaign.Cm.Pipelines.DispatchNewsletter.DeployAnalytics”.
So, I opened the source code and found the following:
private Item AddCampaignItem(MessageItem message)
{
Item item = null;
if (message.MessageType != MessageType.Undefined)
{
item = _itemUtil.GetItem(message.CampaignPosition);
}
if (item == null)
{
item = _itemUtil.GetItem("{C1B8669B-C41A-4ED3-BF0D-E859CF880D42}");
}
Util.AssertNotNull(item);
Item destinationFolderItem = _itemUtil.GetDestinationFolderItem(item);
Util.AssertNotNull(destinationFolderItem);
destinationFolderItem = _itemUtil.GetItem(destinationFolderItem.ID, message.InnerItem.Language, allowOtherLangs: false);
Util.AssertNotNull(destinationFolderItem);
Item item2 = _itemUtil.AddSubItemFromTemplate($"{message.InnerItem.Name}{message.MessageId:D}", message.InnerItem.DisplayName, new TemplateID(AnalyticsIds.Campaign), destinationFolderItem);
Util.AssertNotNull(item2);
item2.Editing.BeginEdit();
item2[new ID("{0F47D1B4-BCB4-4F7F-9065-6ECB46AAB9A1}")] = item2.Name;
item2[new ID("{43AA1C9A-D1BE-498A-9841-1DEF2C2231BA}")] = "{3E11F7A7-0059-45EF-95D9-3B03425B3BAF}";
if (item2.Fields.Contains(new ID("{47B4D72E-5DFD-44B4-BD9B-8C360363F887}")))
{
item2[new ID("{47B4D72E-5DFD-44B4-BD9B-8C360363F887}")] = "{EB042E92-6C2A-4A65-92EE-F74D21B3107D}";
}
DateTime dateTime = _currentDateProvider.UtcNow();
item2[new ID("{BD4720D7-9ED6-4438-959B-7B1C5C32C10B}")] = DateUtil.ToIsoDate(dateTime);
item2.Editing.EndEdit();
message.Source.CampaignId = item2.ID;
message.Source.StartTime = dateTime;
return item2;
}
Sitecore is trying to create a Campaign for analytics in the background. On line 18, we can see it is actually combining “Email Item.Name + MessageId”. If our email name is 74 characters and, on top of that, the MessageId (GUID) is 36, it exceeds MaxItemNameLength.
During the above process, it is executing “Sitecore.Data.Items.ItemUtil.GetItemNameError” from Sitecore Kernel, where the following validation makes our email send fail. (The typo in “length” is from the source code.)
if (name.Length > Settings.MaxItemNameLength)
{
return Translate.Text($"An item name lenght should be less or equal to {Settings.MaxItemNameLength}.");
}
So, the issue is clearly a Sitecore bug. We found three possible solutions:
1. Override “Sitecore.EmailCampaign.Cm.Pipelines.DispatchNewsletter.DeployAnalytics” and fix the campaign name.
2. Add validation so users can’t enter an email name longer than 64 characters.
3. Increase the Sitecore “MaxItemNameLength”.
With the first approach, we were concerned about the suffix of the campaign name, the MessageId, which might be used for something else internally. It looks like this:

The second approach can be achieved by setting maxLength in the Sitecore core database. The steps are:
i. Select the core database and browse to this item in the content tree: “sitecore/client/Applications/ECM/Pages/Messages/Regular/PageSettings/Tabs/General”.
ii. (Thanks to Maarten for this) Open the presentation details, find the first textbox rendering (its ID should be “NameTextBox”) and change MaxLength. It looks like this:

The third approach is very straightforward: just change the MaxItemNameLength in Sitecore.config or create a patch to override it.
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<settings>
<setting name="MaxItemNameLength" set:value="150" />
</settings>
</sitecore>
</configuration>
We raised a Sitecore ticket and got the following reply:
We have registered this behavior as a bug.
To track the future status of this bug report, please use reference number 365930. More information about public reference numbers can be found here: https://kb.sitecore.net/articles/853187
As a workaround, please increase the value of MaxItemNameLength in Sitecore.config. For example, by changing the value to 150. Or you can shorten the message name as what you have mentioned previously.
Thanks
Munir