Email Notifications In Merchello

  • Posted By: Lee Messenger
  • Tagged: Notifications

In this blog post we are going to explain about Notification's in Merchello and also walk you through setting up an Order Confirmation email notification.

The built in Notification provider is the ‘Email Notification’ provider, which as the name infers, is responsible for sending email (SMTP based) messages – This is what we’ll use in a moment to send the Order Confirmation.

What are Notifications?

Notifications are loosely coupled with a set of “Triggers” and “Monitors”.  Triggers notify “subscribing” Monitors that it should, in this case, send an email using a model it passes to format the body content.

It is important to make the distinction between “Triggers” and “Events.”  Merchello does not use events to send notifications - it uses explicitly called triggers to allow for more granular control of if and when an appropriate Notification process should be executed.

Note: The OrderConfirmation trigger sometimes confuses people that are first starting out in Merchello as it is generally triggered by Payment Provider developers once a payment has been authorized - so it “appears to act like an event” but in fact it is executed in the provider with code similar to:

Notification.Trigger("OrderConfirmation", paymentAttempt, new[] { "some@email.com" });

The default SMTP Notification Provider, utilizes the triggers and monitors  to send one or more messages for any configured monitor. 

When a trigger is executed, any monitor subscribing to the trigger looks to see if it has any associated messages. If there are any messages, the monitor instantiates a formatter to format the message body and for each message passes the message and formatter off to be sent. 

Assume in the diagram below that the Trigger is an “OrderConfirmation” trigger. 

Monitor 1 has 3 messages associated with it through the back office.  When the trigger is executed Monitor 1 creates a Razor formatter and sends the 3 messages through the SMTP Notification provider. 

The messages could be completely different if a separate razor files were used to create the message bodies. They could also have different recipients so you could have:

  • An email for the customer
  • An email for the store owner
  • An email for a drop shipper

notification-diagram

Configuring Email (SMTP) Notifications

Merchello’s SMTP Notification provider allows for creating and triggering highly customizable emails for a set of resolvable “Triggers”. I’m going to walk you through configuring a razor based email notification for an Order Confirmation email.

  • Activate the SMTP Notification provider by going to the ‘Gateway Providers’ tab and clicking the “Lightbulb” icon next to the ‘SMTP Notification Provider’.

activate-notification.png

Once the notification provider has been activated we can add and configure “Notification Methods” for the provider.

  • Click the “Notification” tab to bring you to the notification method configuration screen

notification-method.png

  • Click the “Add a Notification” link and select “Email Notification” from the drop down click ‘Add’ and then simply hit save in the dialog box that opens.

  • Click the “Add message” link to add a message to the Email Notification method

    add-notification-message.png

  • Enter the “From Email Address” in the box provided.  This is the email address the notification will be sent from and then click ‘Save’

    email-setup.png

  • Click the new “Order Confirmation” link to create and edit the message contents.

    order-confirmation-link.png
  • Click “Save” to create/save the message (Currently we need to do this before creating the file below)
  • Click the “Create” button - this will create a new razor file in /Views/Merchello/Notifications/ named OrderConfirmation.cshtml and display a basic editor for editing the razor view.

email-message-creation.png

Editing the razor file is actually easier to do in Visual Studio due to fact you will be able to make use of intellisense. 
  • Edit the message body through the view editor or Visual Studio.  Cut and paste the code below into the view.
@inherits Merchello.Web.Mvc.MerchelloHelperViewPage<Merchello.Core.Models.MonitorModels.IPaymentResultMonitorModel>
@using Merchello.Core
@using Merchello.Core.Models

Dear @Model.Invoice.BillToName

<p>Thank you for your order.</p>
<ul>
    @foreach (var item in Model.Invoice.Items)
    {
        <li>@item.Name + @item.Price.AsFormattedCurrency()</li>
    }
</ul>

<p>Thanks!</p>
  • Click the Save button to save the view.

This completes the notification configuration. You will now need to add some valid SMTP credentials into the web.config or use a local pickup directory for the emails.

The code example below will save all emails from the application into a folder on your C: drive called ‘maildrop’, just update your web.config updating the folder location to suit (You need to have IIS installed on your computer for this to work):

<smtp deliveryMethod="SpecifiedPickupDirectory"> 
<specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop"/> 
</smtp>

Become A Merchello Solution Partner

Merchello's goal is to make you and your clients successful.

Because the needs of every partner are different, we offer two levels of partnership - Gold and Silver.

Each level has unique benefits, all with the goal of connecting partners to our community and helping them succeed.

Apply Today!

  • Get Listed On the official Merchello website
  • Priority Placement Get your business noticed
  • Get Merchello Leads From the Merchello website
  • Premium Support For your Merchello projects
  • Discounts On official Merchello plugins
  • Your Company Featured In our Newsletter