New Custom Email

How do you create and send a new customized email in a similar pattern to the OrderConfirmationEmail?

I have:

  • Created a new email template following the documentation “Add new email template” at [1] (renamed copy of ConfirmationEmail.html)…
  • Added the new class name as a field in PageTemplateNameConstants.cs.
  • Created and renamed a copy of OrderConfirmationPageByFieldTemplateCache in PageByFieldTemplateCache.cs assigning the field Name with the value of the new field in PageTemplateNameConstants.cs
  • Created a copy of OrderConfirmationPageTemplateSetup.cs replacing the parameter PageTemplateNameConstants.OrderConfirmation with the new field added above and changing the class and file names to reflect its new purpose.
  • Created a copy of OrderConfirmationEmail.cs replacing OrderConfirmationPageByFieldTemplateCache with my new class and renamed the class and file names.
  • Added a new mapping to _controllerMapping in FieldTemplateSetupDecorator.cs with the area type WebsiteArea, id as the value of the new field in the PageTemplateNameConstants, controller type as the OrderController and the action as the name of a new function in OrderController.
  • Added a new [HttpGet] function to OrderController.cs with the same name as the above mentioned action string and following the same pattern as the Confirmation function in the same file.
  • Added IoC.Resolve().SendEmail(…) with my new email class as an entry action to OrderState.WaitingConfirmation.

In this scenario OrderConfirmationEmail works, however, the copy does not. The issue appears to be that Page cannot be retrieved in the OrderConfirmationEmail class copy, it fails at or near TryGetPage. I would guess that the new email page is not registered properly, and I am not sure how I would do that correctly.

  1. https://docs.litium.com/documentation/litium-accelerators/develop/front-end/accelerator-email

Litium version: 7.1

Did you create the order confirmation page in the backoffice, using the new class name you created in PageTemplateNameConstants?

1 Like

@ton.nguyen
Nothing has been edited and or added directly in backoffice.
(I would prefer it that way)

If you debug the MailServiceImpl in Accelerator:

  • Is that returning without sending the mail?
  • Do you have any exception?

TryGetPage, in PageByFieldTemplateCache, calls GetCacheItems which returns zero items which then fails the if statement and returns null, thus assigning Page with null, in MailServiceImpl the _urlService.GetUrl(page, …) is called with null and throws a NullReferenceException.

You need to create a page, maybe that page needs to be published also. That is why PageByFieldTemplateCache returns null, it cannot find the page.

1 Like

Ok thanks, this was the issue.
Also, the page did need to be published too.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.