Send Sitecore Forms to a fixed email address

This page was updated on June, 10th 2018 to reflect the changes in v1.2.

Download Sitecore Forms Extensions on github.

With Sitecore 9, the new Sitecore Forms module was introduced. With 9.0.1 the integration with Sitecore Email Experience Manager (EXM) was added.

Whilst this module looks very promising, the functionality is currently limited. One of the features that is mostly missed, if the ability to send the filled in form to a predefined email address. Currently, it is only possible to send an email to the contact that filled in the form (and even in this case you need to make sure the contact is identified in xDB). Furthermore, you cannot use the data of that form in your email.

 

Luckily, Sitecore did provide us with solid documentation on how to create custom save actions and the new xConnect module. By putting those examples together and some additional code we can create a custom save action to mail the form content to an email address that can be specified on the Sitecore form in the backend.

In this solution we will send our email with the EXM platform. Even if you are not planning on doing mass newsletter mailings, EXM is still a nice fit to bundle your system email messages. If you are not doing mass mailings, you can choose a local provider for EXM with a custom mailserver to reduce the costs.

Sitecore Forms Extensions

The custom save action “Send email” is part of the Sitecore Forms Extensions module available in the Sitecore Marketplace. It support sending mails to the current identified contact, a fixed email address or a value from another field.

The action makes the filled in form values available as tokens to be used in the composed email.

The source code can be found on Github.

How to install

Sitecore Forms Extensions is just a Sitecore package that can be downloaded and installed. There is no configuration required to you the new submit action.

Usage

Prerequisites

We assume you have a running Sitecore 9.1 environment with EXM enabled and working.

Create EXM mail template

Go to Email Experience Manager and create a new automated message.

Take any of the available templates, or create your own custom template.

Fill in the general info like “from” name and email.

Then we need to fill in the message.

The message can be anything you want, to get the data from the form into your mail template you need to enter tokens that will be replaced upon sending the mail.

There are 2 options available here:

  1. One token to rule them all
  2. Add field per field

One token to rule them all

When you enter $formFields$ somewhere in the mail, it will be replace with a list of all the fieldnames and their values in the template.

Add field per field

Each field value is also available as a token under the format $form_fieldname$

Finally, we need to activate the message in the delivery tab.

Create Form

Create a basic form with Sitecore Forms make sure to add a submit button.

On the submit button, go to submit actions and add the send email to fixed address action.

Send to current contact

Choose your created EXM template.

Pick mailto “current xDB contact’s email address.

Just like the sitecore build in ‘send email campaign message’ submit action, this will send the exm mail to the current identified contact. However, using the send email action from the Sitecore Forms Extensions module will make the forms field values available as tokens for the composed email.

Send to fixed email address

Choose your created EXM template.

Choose mailto “Fixed Email Address”

Fill in the email addresses the mail needs to be send to. Use a semicolon to specify multiple addresses.

 

Send to form field value

Choose your created EXM template.

Choose mailto “Value from field in form”

Choose one of the fields of the form. This field must contain an email address. It can be a free email field for the visitor to enter it’s email address or it could also be a dropdown with choices that have an email as value. (For example if you want to mail to a different department based on a chosen topic).

Add form to page

Finally, we just need to add the form to a page and make sure everything is published.

That’s it!

 

How does it work?

The full source code is available on Github.

In short, these are the steps were taken in order to create the custom “Send to fixed address” submit action:

  • Create a speak dialogue for our custom save action to enter the fixed mail address
  • Create some code the save action must execute
  • Define custom save action and link it to dialogue

Create dialogue window with Speak

We started from a copy of the existing “Send Email Campaign Message”.

We only needed to add a second field to enter the fixed mail address.

  1. In the core database go to /sitecore/client/Applications/FormsBuilder/Components/Layouts/Actions
  2. Duplicate SendEmailCampaignMessage and name it SendEmailToFixedAddress
  3. Under the form directory, add an item of the type FormTextBoxParameters
  4. On the presentation details of the SendEmailToFixedAddress node, open the properties of the form control, edit the ConfigurationItem to the relative duplicated version in the behaviour section.
  5. On the same presentation details edit the properties of the pagecode. Set the PageCodeScriptFileName to /sitecore/shell/client/Applications/FormsBuilder/Layouts/Actions/SendEmailToFixedAddress.js

Write some code

The SendEmailToFixedAddress class that will be triggered when the form is submitted, extends from SubmitActionBase.

Our code needs to do these steps:

  • Lookup or create a “system”-contact in xDB with the fixed email address
  • Parse the form data and pass it on to EXM through custom tokens
  • Send out EXM campaign to the “system”-contact and the tokens

Create submit action item

In the master database: /sitecore/system/Settings/Forms/Submit Actions/ duplicate the Send Email Campaign Message.

We need to update the Model Type field to our custom save action class that will be created later on.

We will have to change the editor to our one we have just created.

 

 

9 Responses to “Send Sitecore Forms to a fixed email address”

Author's gravatar

Very good to see all this work!
just a note to say it was 9.0.1 not 9.1 in your opening sentence.
With Sitecore 9, the new Sitecore Forms module was introduced. With 9.0.1 the integration with Sitecore Email Experience Manager (EXM) was added.

    Author's gravatar

    Thanks for the feedback John! I have updated the post and corrected the version mistake.

Author's gravatar

Many thanks for sharing this post.

Truly remarkable, was very useful in customizing Forms 9 !

Cheers.

Author's gravatar

Very useful and working fine for fixed email and also from form field value.
But for me i need to add “CC” and “BCC” for this send email action. Please help me out from this.

    Author's gravatar

    CC and BCC are currently not supported by the module, nor are there any plans to do so.
    Furthermore, EXM currently has no feature to add CC or BCC onto an email, so currently this request is not possible.

Author's gravatar

Hi,
I have a question regarding this but I am not sure if it is in the scope of this article.
When I try to activate the message it pops up the following error message: “Failed to connect to the email server. Please try again later.”

On the Sender Details – From Email I specified an email which ends with @noreply.com. Might this be the problem?

Thanks

Author's gravatar

Hi,
after installing the package into my Sitecore 9.1 instance, created the automated email via EXM and created the form I have noticed that the email is never sent. Can you please help me out with this? I am a bit struggling with this now.

Thanks

Author's gravatar

Hi,
when i am trying to bind image dynamically in body i am getting error like “ECM.Pages.Message.ImagesAreNotAvailable”

Below line i am using in Body area

where $form_ArtWorkImage$ i will get dynamically.

Thanks

Leave a Reply to Harish Immadi