Sitecore Submit Action – Send Notification Email using Sitecore Dispatch Manager

I’m going to walk you through how to use Sitecore Dispatch Manager to implement Send Notification Email for Submit Action in Sitecore Form Submissions.

Let’s go ahead and create Form Submit Action.

Sitecore Item Path: /sitecore/system/Settings/Forms/Submit Actions/Send Notification Email

Add “Send Notification Email” action on the Submit button.

Now let’s write the code for CustomSendNotificationEmail class

You’ll need the following references in the solution:
Sitecore.ExperienceForms
Sitecore.ExperienceForms.Mvc
Sitecore.ExperienceForms.SubmitAction
Sitecore.EDS.Core

On the line 32 you will see DeserializeObject to EmailFormDefinition object. Create a new EmailFormDefinition Model class and add the reference in the CustomSendNotificationEmail class.

Now we need EmailManager class to send an email using DispatchManager.

That’s it with the code 🙂

On the CMS go the form Submit Action “Send Notification Email” and add the following parameters:

{“emails”:[nikkipunjabi@outlook.com],”fromEmailName”:”CompanyName Notification”,”emailSubjectLine”:”Complaint Form Submission”,”fromEmailId”:no-reply@comms.COMPANYNAME.ae}


Please Note: in the emails — you can add Multiple ToEmailAddresses. You can set Emails (To Email Address), From Email Name (Sender Name), From Email Id (Sender Email ID), Email Subject Line

Output:

The development of this feature can be improved in many ways but it depends entirely on your requirements and availability of time. For example, adding or editing parameter values directly on the form submit action on Sitecore Forms. The Sender Name and Sender Email Address should be configured from the configuration items, and the Email Body can be customized directly from the CMS. Alternatively, if the SMTP configuration is using Custom SMTP and it allows you to set the sender email address to any address, you can have the reply email go to the actual user who submitted the form.

Challenges:

#1 – Execute Method is not getting triggerred.

Solution: First check the breakpoint on the class constructor – in my case, breakpoint was hitting on the class constructor but not the execute method. The reason was simple, “Send Notification Email” action item was in the end while “Redirect To URL” action item was before that.

#2 – data.Chilkat fail reason: “DataFailure”

Solution: In our case, I spent a lot of time figuring out that Sitecore Email Cloud only supports a specific Email Address as the From Email Address. It does not support having other email addresses as the From Email Address. When I entered no-reply@comms.companyName.com – it started working and we received a proper notification email upon form submission. If my understanding is incorrect, Email Cloud will not allow us to enter another domain for the Sender Email Address. It will only allow DKIM verified domains to send an email using Email Cloud. You can correct me by adding comments if I am wrong in this regard.

References:

https://www.xcentium.com/blog/2019/04/11/how-to-send-custom-email-using-sitecore-dispatch-manager-and-test-it-locally

Share

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.