Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
Message and Notification
Purpose
Create, modify, and review GrandNode email message templates, DotLiquid tokens, message sending flows, queued email lifecycle, and domain event notification handlers.
When To Use
Use this skill when adding or changing a message template, adding new DotLiquid tokens or drop properties, triggering a new email notification from business code, seeding message templates in the installer, extending an existing Liquid* drop class, or wiring a mediator event handler that sends a notification.
When Not To Use
Do not use this skill for general admin UI work, settings, or localization changes beyond message template resource keys; combine it with admin-area-changes or settings-and-localization when those are also involved.
Do not use this skill as the primary review for MongoDB queries or security; combine with the relevant skill when those concerns apply.
Inputs Required
- Repository root.
- Trigger event or business action that should send the notification.
- Recipient type: customer, store owner, vendor, or arbitrary address.
- Domain entities whose data must appear in the template body.
- Whether the template is new or an existing one is being updated.
- Required subject line and HTML body structure.
Instructions
Mandatory Rules
Message Templates
- Define the template name as a
public const stringinMessageTemplateNamesatsrc/Business/Grand.Business.Messages/Services/MessageTemplateNames.cs. Follow the existingSubject.RecipientNotificationnaming convention. - Seed the default template in
src/Modules/Grand.Module.Installer/Services/InstallDataMessageTemplates.csinsideInstallMessageTemplates(). Every seeded template must reference a default email account, setIsActive = true, and include a valid DotLiquidSubjectandBody. - Keep template
Nameconsistent with the constant defined inMessageTemplateNames. Code that sends the template looks it up by this name. - Use
ITranslationEntity.LocalesonMessageTemplatefor per-language subject and body overrides. Never store language-specific copies as separate documents. - Only use tokens that are exposed by the relevant
Liquid*drop classes or byLiquidStore. Do not invent tokens that have no backing drop property. - Use DotLiquid syntax:
{{Drop.Property}}for values,{% if condition %}...{% endif %}for conditions,{% for item in Collection %}...{% endfor %}for loops.
Sending Messages
- Add a typed send method to
IMessageProviderServiceinsrc/Business/Grand.Business.Core/Interfaces/Messages/IMessageProviderService.cswhen the trigger is a recurring, well-defined business event. Follow the signature pattern:Task<int> SendXxxMessage(TEntity entity, Store store, string languageId); - Implement the method in
MessageProviderServiceatsrc/Business/Grand.Business.Messages/Services/MessageProviderService.cs. The standard implementation pattern is:- Get
MessageTemplateby name usingIMessageTemplateService.GetMessageTemplateByName(name, store.Id). - Return 0 if the template is not active.
- Resolve
EmailAccountusing the template'sEmailAccountIdandIEmailAccountService. - Build tokens with
LiquidObjectBuilderusing the appropriateAddXxxTokens()methods. - Call
await builder.Build()to get the populatedLiquidObject. - Call
await SendNotification(messageTemplate, emailAccount, languageId, liquidObject, toEmail, toName).
- Get
- Use the generic
SendNotificationoverload directly when a one-off or plugin-triggered send does not justify a dedicated typed method.
DotLiquid Drops and Tokens
- Add new token properties to an existing
Liquid*drop class insrc/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/when the data already belongs to that drop's entity. Do not add properties that require loading additional entities unless those are already available in the drop constructor. - Add a new drop class inheriting from
DotLiquid.Droponly when the new template uses a domain entity that has no existing drop. Place it in the drops folder and wire it via a newGetXxxTokensCommandfollowing the pattern of existing token commands undersrc/Business/Grand.Business.Core/Commands/Messages/Tokens/. - Handle
MessageTokensAddedEventin anINotificationHandlerto inject extra tokens from a plugin without modifying core drop classes. The event carries theMessageTemplatename and the currentLiquidObject. - Never access
ITranslationService, repositories, or services directly from inside aLiquid*drop property getter. Populate all values in the command handler that constructs the drop.
Queued Emails
- All outgoing emails are persisted as
QueuedEmaildocuments before they are sent.SendNotificationqueues the email viaIQueuedEmailService.InsertQueuedEmail. Never callIEmailSenderdirectly from business code. - Respect
MessageTemplate.DelayBeforeSendandMessageTemplate.DelayPeriodId—SendNotificationconverts these toQueuedEmail.DontSendBeforeDateUtc. Do not override or ignore the delay. - The scheduled task
QueuedMessagesSendScheduleTaskinGrand.Module.ScheduledTaskssends queued emails. Do not introduce an alternative sending path.
Domain Events and Handlers
- Raise domain events via
IMediator.Publish(new XxxEvent(...))after the triggering business action completes. Do not publish inside a repository or data layer. - Implement
INotificationHandler<TEvent>in the relevantGrand.Business.*project when the notification should be sent in response to a domain event. - Register event handlers automatically —
Grand.Mediatorscans assemblies registered in startup. No explicit handler registration is required beyond ensuring the assembly is included.
Recommendations
- Prefer adding a property to an existing drop over creating a new drop when the entity is already available in the build pipeline.
- Prefer the
MessageTokensAddedEventhandler for plugin-specific tokens rather than modifying core drop classes. - Prefer reusing
{{Store.Name}},{{Store.URL}}, and{{Store.AdminEmail}}tokens that are always available viaLiquidStore. - Prefer the
Referenceenum field onQueuedEmail(e.g.,Reference.Order,Reference.Customer) to link queued emails to the source entity for audit purposes. - Prefer testing
MessageProviderServicewith a mockIMessageTemplateServicethat returns a pre-builtMessageTemplateto verify the queuing call.
Constraints
- Never hardcode email addresses in
SendXxxmethods; always resolve them fromEmailAccountor from the entity being notified. - Never bypass
IQueuedEmailService; do not call SMTP directly from business or web code. - Never use tokens that are not backed by a drop property — they will render as empty strings.
- Never add rendering logic (formatting, currency, date) to drop property getters unless the same pattern is already used in that drop.
- Never store multiple language copies of a template as separate
MessageTemplatedocuments; use theLocalescollection. - Never call
IMessageProviderServicefrom inside a Razor view or a controller action directly — trigger sends from handlers or services.
Key Contracts
IMessageProviderService (src/Business/Grand.Business.Core/Interfaces/Messages/IMessageProviderService.cs)
Typed send methods follow the pattern:
Task<int> SendCustomerRegisteredMessage(Customer customer, Store store, string languageId);
Task<int> SendOrderPlacedCustomerMessage(Order order, Customer customer, Store store, string languageId);
// ... one method per template
Generic send:
Task<int> SendNotification(
MessageTemplate messageTemplate, EmailAccount emailAccount,
string languageId, LiquidObject liquidObject,
string toEmailAddress, string toName,
string attachmentFilePath = null, string attachmentFileName = null,
IEnumerable<string> attachedDownloads = null,
string replyToEmailAddress = null, string replyToName = null,
string fromEmail = null, string fromName = null, string subject = null,
Reference reference = Reference.None, string objectId = "");
LiquidObjectBuilder (src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/LiquidObjectBuilder.cs)
var liquidObject = await new LiquidObjectBuilder(_mediator)
.AddStoreTokens(store, language, emailAccount)
.AddOrderTokens(order, customer, store, host)
.AddCustomerTokens(customer, store, host, language)
.Build();
MessageTokensAddedEvent (src/Business/Grand.Business.Core/Events/Messages/MessageTokensAddedEvent.cs)
public class MessageTokensAddedEvent : INotification {
public MessageTemplate Message { get; }
public LiquidObject LiquidObject { get; }
}
File Locations
| Concern | Path |
|---|---|
| MessageTemplate entity | src/Core/Grand.Domain/Messages/MessageTemplate.cs |
| QueuedEmail entity | src/Core/Grand.Domain/Messages/QueuedEmail.cs |
| EmailAccount entity | src/Core/Grand.Domain/Messages/EmailAccount.cs |
| MessageTemplateNames constants | src/Business/Grand.Business.Messages/Services/MessageTemplateNames.cs |
| IMessageProviderService interface | src/Business/Grand.Business.Core/Interfaces/Messages/IMessageProviderService.cs |
| MessageProviderService implementation | src/Business/Grand.Business.Messages/Services/MessageProviderService.cs |
| IMessageTemplateService interface | src/Business/Grand.Business.Core/Interfaces/Messages/IMessageTemplateService.cs |
| IQueuedEmailService interface | src/Business/Grand.Business.Core/Interfaces/Messages/IQueuedEmailService.cs |
| IEmailAccountService interface | src/Business/Grand.Business.Core/Interfaces/Messages/IEmailAccountService.cs |
| IEmailSender interface | src/Business/Grand.Business.Core/Interfaces/Messages/IEmailSender.cs |
| DotLiquid drop classes | src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/ |
| LiquidObjectBuilder | src/Business/Grand.Business.Core/Utilities/Messages/DotLiquidDrops/LiquidObjectBuilder.cs |
| Token commands | src/Business/Grand.Business.Core/Commands/Messages/Tokens/ |
| MessageTokensAddedEvent | src/Business/Grand.Business.Core/Events/Messages/MessageTokensAddedEvent.cs |
| IMessageTokenProvider interface | src/Business/Grand.Business.Core/Interfaces/Messages/IMessageTokenProvider.cs |
| MessageTokenProvider implementation | src/Business/Grand.Business.Messages/Services/MessageTokenProvider.cs |
| Installer — template seed | src/Modules/Grand.Module.Installer/Services/InstallDataMessageTemplates.cs |
| Send scheduled task | src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/QueuedMessagesSendScheduleTask.cs |
| Tests | src/Tests/Grand.Business.Messages.Tests/Services/ |
Available Liquid Drops
| Drop class | Token prefix | Entity |
|---|---|---|
LiquidStore |
{{Store.*}} |
Store, EmailAccount |
LiquidCustomer |
{{Customer.*}} |
Customer |
LiquidOrder |
{{Order.*}}, {{Order.OrderItems}} |
Order, OrderItem |
LiquidShipment |
{{Shipment.*}} |
Shipment |
LiquidProduct |
{{Product.*}} |
Product |
LiquidMerchandiseReturn |
{{MerchandiseReturn.*}} |
MerchandiseReturn |
LiquidGiftVoucher |
{{GiftVoucher.*}} |
GiftVoucher |
LiquidNewsLetterSubscription |
{{NewsLetterSubscription.*}} |
NewsLetterSubscription |
LiquidVendor |
{{Vendor.*}} |
Vendor |
LiquidBlogComment |
{{BlogComment.*}} |
BlogComment |
LiquidNewsComment |
{{NewsComment.*}} |
NewsComment |
LiquidProductReview |
{{ProductReview.*}} |
ProductReview |
LiquidContactUs |
{{ContactUs.*}} |
ContactUs |
LiquidAskQuestion |
{{AskQuestion.*}} |
AskQuestion |
Expected Output
Produce one of these results:
- A new or modified message template with matching constant, installer seed, send method, drop properties, and test.
- A review report listing message and notification issues by severity.
- A plugin token extension using
MessageTokensAddedEventwithout modifying core drops.
Include changed files, token list, installer seed status, queuing behavior, and remaining risks.
Validation Checklist
- Template name constant added or updated in
MessageTemplateNames. - Template seeded in
InstallDataMessageTemplateswith active flag and email account. - Template name matches constant and lookup key in
SendXxxmethod. - Only tokens backed by existing drop properties are used in subject and body.
- New drop properties are populated in the command handler, not in the getter.
-
LiquidObjectBuilderincludes all requiredAddXxxTokens()calls. - Send method calls
GetMessageTemplateByName, resolvesEmailAccount, builds tokens, and callsSendNotification. - Early return when template
IsActive == false. - Emails are queued via
IQueuedEmailService;IEmailSenderis not called directly. - Template delay is not overridden in the send method.
- Domain event handlers are in the correct
Grand.Business.*project. - Tests cover the send method queuing call and inactive-template early return.
Examples
Example 1: New Order Status Email
Input: Send an email to the customer when an order reaches a custom "Ready for pickup" status.
Output:
- Add
const string SendOrderReadyForPickupCustomerMessage = "OrderReadyForPickup.CustomerNotification"toMessageTemplateNames. - Seed the template in
InstallDataMessageTemplateswith subject"Your order {{Order.OrderNumber}} is ready"and a body using{{Order.*}}and{{Store.*}}tokens. - Add
Task<int> SendOrderReadyForPickupCustomerMessage(Order order, Customer customer, Store store, string languageId)toIMessageProviderService. - Implement the method in
MessageProviderService: load template by name, return 0 if inactive, buildLiquidObjectBuilderwithAddStoreTokens+AddOrderTokens+AddCustomerTokens, callSendNotificationwith the customer's email. - Publish
OrderReadyForPickupEventfrom the order status-change service and handle it in aINotificationHandler<OrderReadyForPickupEvent>that calls_messageProviderService.SendOrderReadyForPickupCustomerMessage(...).
Example 2: Plugin Token Extension
Input: A loyalty plugin needs to include a customer's loyalty points balance in existing order emails.
Output:
- Create an
INotificationHandler<MessageTokensAddedEvent>in the plugin. - In
Handle, checknotification.Message.Nameto filter only the relevant templates. - Load the loyalty balance for the customer referenced in the existing
LiquidCustomerdrop onnotification.LiquidObject. - Assign a new
LiquidLoyaltyPointsdrop (or a simple string property) tonotification.LiquidObject. - Use
{{LoyaltyPoints.Balance}}in the template body — it resolves from the drop set onLiquidObject. - No changes to core drop classes are needed.
Example 3: Update Existing Template Body
Input: Add the vendor name to the existing shipment sent email.
Output:
- Confirm
LiquidShipmentorLiquidVendoralready exposes a vendor name property; if not, add the property to the drop and populate it inGetShipmentTokensCommand. - Update the
ShipmentSent.CustomerNotificationbody inInstallDataMessageTemplateswith the new token (for new installations). - Provide a migration that updates the template body for existing installations in
Grand.Module.Migration.