---
title: Custom form autoresponder emails
related:
  - https://docs.kentico.com/documentation/business-users/digital-marketing/forms/create-and-edit-forms.md
  - https://docs.kentico.com/documentation/business-users/digital-marketing/emails.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

[Forms](https://docs.kentico.com/documentation/business-users/digital-marketing/forms.md) provide the option to automatically send an email message to every user who submits the form.

For most scenarios, we recommend that you prepare the autoresponder email content directly in the Xperience administration using an email channel application (see [Emails](https://docs.kentico.com/documentation/business-users/digital-marketing/emails.md)), and then select an appropriate email for each form.

However, you may need to implement custom emails if you require advanced or dynamic autoresponder content. For example, you can develop a promotional code generator, and then prepare custom form autoresponder emails containing the value generated for every recipient.

> **Note:** **Prerequisite**
>
> To allow the system to send out emails, you first need to set up and configure an email client (for example an SMTP server or SendGrid integration). For more information, see [Email configuration](https://docs.kentico.com/documentation/developers-and-admins/configuration/email-configuration.md).
>
> **Email statistic tracking not available**
>
> The system does not [track statistics](https://docs.kentico.com/documentation/business-users/digital-marketing/emails/track-email-statistics.md) for custom form autoresponder emails. Tracking functionality is only available for emails created using an email channel application in Xperience.

## Custom form autoresponder emails

To enable custom form autoresponder emails for a form:

1. Open the **Forms** application in Xperience.
2. Select the form in the list.
3. Select **Autoresponder** in the options panel on the right.
4. Choose the **Custom** option.
5. Select **Save**.

Until developers prepare and register customized emails, the **Custom** autoresponder sends a basic thank you email with the following parameters:

| **From**    | no-reply@localhost.local<br>The sending domain in the default From address reflects the [global sending domain for system emails](https://docs.kentico.com/documentation/developers-and-admins/configuration/email-configuration.md), for example: _no-reply@company.com_ |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **To**      | \&lt;email address of the [contact](https://docs.kentico.com/documentation/business-users/digital-marketing/contact-management.md) who submitted the form>                                                                                                                |
| **Subject** | Thank you for filling out the form                                                                                                                                                                                                                                        |
| **Body**    | We appreciate the information you provided us in the submitted form. Thank you and have a nice day.                                                                                                                                                                       |

This thank you message will not be suitable for most forms on real-world websites. Developers need to override the custom autoresponder emails with appropriate content based on the website's branding and the context of each specific form. The emails can also include values that the user entered into the form.

1. Open your project's solution in Visual Studio.
2. [Add a custom assembly](https://docs.kentico.com/documentation/developers-and-admins/customization/integrate-custom-code.md) (_Class Library_ project) to your solution or re-use an existing one.
3. Create a new class that implements the `IFormSubmitAutomationEmailProvider` interface.
4. Define the `GetEmail` method:
   - The method provides the following parameters:
     - `BizFormInfo` – the form that was submitted. For example, you can evaluate the form's `FormName` property to branch your code and create different autoresponder emails for specific forms.
     - `BizFormItem` – the data that the user submitted into the form. Use the `GetValue(<FieldName>)` method to access the values of form fields (or the alternative _GetValue_ methods).
     - `ContactInfo` – the [contact](https://docs.kentico.com/documentation/business-users/digital-marketing/contact-management.md) who submitted the form.
   - Return an `AutomationEmail` object with the content and other parameters of the form autoresponder email. The object exposes standard email properties: `Subject`, `Body`, `Sender`, `Recipients`.
   - Return `null` in cases where you cannot or do not wish to send an autoresponder email.
5. Register your custom implementation by adding the `RegisterImplementation` assembly attribute.

The system now sends emails according to your custom implementation whenever a user submits a form with the **Custom** autoresponder.

> **Tip:** You can reuse or fall back to the default `IFormSubmitAutomationEmailProvider` implementation. See [Decorate system services](https://docs.kentico.com/documentation/developers-and-admins/customization/decorate-system-services.md) for more information.

```csharp title="Example"
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using CMS;
using CMS.ContactManagement;
using CMS.OnlineForms;

using CMS.Automation;

// Registers the custom IFormSubmitAutomationEmailProvider implementation
[assembly: RegisterImplementation(typeof(IFormSubmitAutomationEmailProvider), typeof(Custom.CustomFormSubmitAutomationEmailProvider))]

namespace Custom
{
    public class CustomFormSubmitAutomationEmailProvider : IFormSubmitAutomationEmailProvider
    {
        // Stores an instance of the default IFormSubmitAutomationEmailProvider implementation
        private readonly IFormSubmitAutomationEmailProvider defaultAutomationEmailProvider;

        public CustomFormSubmitAutomationEmailProvider(IFormSubmitAutomationEmailProvider defaultAutomationEmailProvider)
        {
            this.defaultAutomationEmailProvider = defaultAutomationEmailProvider;
        }

        // Creates an autoresponder email based on the submitted form
        public Task<AutomationEmail> GetEmail(BizFormInfo form, BizFormItem formData, ContactInfo contact)
        {
            // Gets the email address from the contact's Email attribute
            string recipient = contact.ContactEmail;

            if (string.IsNullOrEmpty(recipient))
            {
                // The user hasn't provided an email address, so no autoresponder email is sent
                return null;
            }

            // Prepares a custom autoresponder email for a form with the 'ContactUs' code name
            if (form.FormName.Equals("ContactUs", StringComparison.InvariantCultureIgnoreCase))
            {
                return Task.FromResult(new AutomationEmail
                {
                    Subject = "Thanks for contacting us",
                    // Builds the email body, including the name of the contact who submitted the form,
                    // and the value of the 'UserMessage' form field
                    Body = $"Hello {contact.ContactFirstName}, <br />" +
                           "thank you for contacting us. You sent us the following message:<br />" +
                           formData.GetStringValue("UserMessage", ""),
                    Sender = "no-reply@company.com",
                    Recipients = new List<string> { recipient }
                });
            }

            // Returns the default form autoresponder email as a fallback
            return defaultAutomationEmailProvider.GetEmail(form, formData, contact);
        }
    }
}
```

> **Note:** **Context data not available**
>
> Autoresponder emails are not sent within the context of a web request, and are internally processed using an automation process. As a result, your `IFormSubmitAutomationEmailProvider` code cannot access context data, such as the current request, website channel or page.
>
> You can get certain context-related data from the `BizFormInfo` and `ContactInfo` parameters of the `GetEmail` method.
