Email Connector

Last modified: August 14, 2025

Introduction

The Email Connector enables you to send and receive emails using your own email server. It supports features like template-based emails, as well as signed and encrypted email sending.

Features

The Email connector includes the following features:

  • Configuration of multiple email accounts
    • Supports Basic Authentication or OAuth 2.0 (Authorization Code Flow or Client Credentials Flow) for Microsoft Entra ID (formerly Azure Active Directory) accounts
    • Supports shared mailboxes with both Basic Authentication and OAuth 2.0
  • Digital signatures and encryption
  • Email templates
  • Sending and receiving emails using OAuth 2.0 Authorization Code Grant or Client Credentials Flow

The Email connector supports the following protocols:

  • POP3 and POP3S
  • IMAP and IMAPS
  • SMTP

Prerequisites

Before you use the Email connector in your app, do the following:

  • Download and configure the latest version of the Mx Model Reflection module. If you have the module already, ensure it is up to date.
  • Download and configure the latest version of the Encryption module. If you have the module already, ensure it is up to date.
  • Download and configure the latest version of the Community Commons module. If you have the module already, ensure that it is up to date.
  • Remove any existing email modules (such as IMAP/POP3 and Email Module with Templates).
  • Remove any orphaned JAR files (including javax.mail-1.6.2.jar, activation-1.1.jar, and commons-email.jar) from any old email modules in the userlib subdirectory.
  • Clean the deployment directory.

Migrating from Another Module

When migrating to the Email Connector from another email module, it is recommended to test your configuration in a separate app first to ensure a smooth transition.

It is recommended to use the community-supported Email Connector Migration Utility module to migrate data from the Email Module with Templates service.

Included Widgets

The following widgets are bundled in the module:

Setup in Studio Pro

After you install the Email connector, configure the following in Studio Pro:

  1. Set a value for the EncryptionKey constant provided by the Encryption module, if you have not already configured it in the Prerequisites.
  2. Launch the user interface by using the ACT_EmailAccount_LaunchEmailConnectorOverview microflow in the USEME > Microflows folder.

Module Security and Roles

The module includes a default EmailConnectorAdmin module role, which comes with access rights designed to cover common use cases. Review and confirm that the access rights meet your specific use case and security requirements before linking this module role to user roles in App Security.

Email Account Configuration

Once you run your Studio Pro app, you can start configuring your email accounts in the Email connector UI.

Adding Email Account

When you run your app to use the Email connector module for the first time (and if no earlier data is present), you will see a welcome screen with an account setup wizard. Click Get Started and follow the steps to add email accounts. The wizard takes you through three steps to configure either your primary email account or a shared mailbox:

  1. Select the authentication method that you want to use. You can choose either Use Basic Credentials or Use Microsoft Entra ID (OAuth 2.0).
  2. Select if you want to configure a primary mailbox or a shared mailbox.
  3. Select your desired protocols for sending and receiving emails.

You can add and configure primary and shared mailboxes in the Email Connector using basic authentication or OAuth 2.0 for Microsoft Entra ID accounts. For OAuth authentication, you can use the authorization code flow or the client credentials flow.

For details on how to configure OAuth 2.0 accounts, see Creating an Account Using Microsoft Azure OAuth 2.0. The account configuration wizard supports automatic and manual configurations for sending and receiving emails.

Automatic Configuration

Based on the entered email address domain, the module will try to fetch configuration details for sending and receiving email. This auto-discovery of configuration works for well-known email domains (including Gmail, Outlook, Yahoo, and Microsoft). If the module fails to detect the email settings automatically, it will prompt you to enter them manually to add the email account.

In Studio Pro, it is also possible to use the GetAutoConfig Java action to get all supported email configurations for the provided user name. This action returns results as Email_Connector.EmailProvider. Process the Email_Connector.EmailProvider records to get the desired configuration and create the Email_Connector.EmailAccount.

Manual Configuration

To manually configure the account for sending and receiving emails, enter the protocol, server host, and server port. Refer to the email server documentation to get this information.

Additional Account Settings

You can choose to adjust the following account settings:

  • Subscribe to incoming emails – Disabled by default. Enable this option if you want to receive notifications for new incoming emails. For modeling purposes, use the SubscribeToIncomingEmail Java action. This feature is supported only for IMAP protocols, and some mail servers may not support it. For more information, see Subscribing to Incoming Email section below.
  • Sanitize email to prevent XSS attacks – Disabled by default, but strongly recommended to enable. When turned on, the connector removes malicious scripts from email content to prevent XSS attacks. For more information, see Sanitize Untrusted HTML (To Prevent XSS).
  • Replicate everything in 'Inbox' folder – Disabled by default. When turned off, the connector retrieves only the number of emails specified in the Number of emails to retrieve from server field, based on the chosen fetch strategy. When turned on, the connector replicates all emails from the specified folder (for example, Inbox) in batches defined by the Email batch size field. Emails are retrieved from oldest to newest.
  • Connection Timeout (milliseconds) – The default value is 20000. Adjust this value in the account settings or the EmailAccount object if you want to change the timeout duration for sending and receiving emails.

Usage

Once you have set up an email account, you can use it in microflow activities to send and receive emails. The steps below cover both Studio Pro usage and runtime behavior for when the connector is running in your app.

Sending Email

When the module is running, click New Email to compose and send new emails.

When modeling your app in Studio Pro, use the SendEmail Java action to send emails. The input parameters are as follows:

  • EmailAccount – email account consisting of the outgoing email configuration
  • EmailMessage – the EmailMessage object to be sent

The return type is a Boolean value. This Java action uses the provided details to connect to the email server and send an email. It returns True if successful and displays the error object and cause if it fails.

When sending an email, the To and Content fields are mandatory. In To, CC, and BCC, you can optionally specify multiple email addresses, each separated by a semicolon (;).

Receiving Email

Click Fetch Emails to receive emails. Emails are fetched in the background and processed by the server, as configured in the email account.

When modeling your app in Studio Pro, use the RetrieveEmailMessages Java action. Once this Java action is called in the background, emails are fetched over multiple Java threads and returned asynchronously. Email fetching continues until the conditions defined in the email account settings are met. For example, you could set the app to fetch the latest 1,000 emails. For more information, see Additional Account Settings.

The input parameters for receiving email are the following:

  • EmailAccount – This is an email account consisting of the incoming email configuration.

  • onEmailFetchMicroflow – This is a microflow that is triggered when List of EmailMessage is fetched from the email server, as per the batch size specified in the email account settings. You can process the list according to your needs.

  • onFetchCompleteMicroflow – This is a microflow that is triggered when the fetch action is successfully completed.

  • onFetchErrorMicroflow – This is a microflow that is triggered if there are errors while fetching from the email server.

Using Email Templates

You can create and use templates with any email account.

Creating an Email Template

You can create email templates in two ways:

  • While running the app, click the Email Templates button and follow the wizard.
  • While modeling the app in Studio Pro, use the SNIP_EmailTemplate_Overview snippet located in Private > Snippets. Use the snippet on a page and save it on a button click.

Creating an Email Message from a Template

When modeling your app in Studio Pro, use the CreateEmailFromTemplate Java action to create a draft message that you can preview and modify. Once your message is ready, you can send it with the SendEmail action.

The input parameters are the following:

  • DataObject – This is an entity object from which you want to extract the placeholder tokens. If you want to retrieve from multiple objects, create a non-persistable entity.
  • EmailTemplate – This is an email template from which an EmailMessage object is created and sent.
  • Queued – When true, the email message is stored in the EmailMessage entity with its status as Queued. In this case, you can send it later using a scheduled event. You can use the microflow SE_SendQueuedEmails to create scheduled events. You can also create a task queue and run this microflow in that task queue to minimize system resource usage. Using a task queue, you can set the number of threads, node or cluster-wide scope, time intervals, and other parameters.

Refer to the sample microflow Sample_ACT_CreateEmailFromTemplateAndThenSend. This microflow demonstrates how to use the CreateEmailFromTemplate Java action and set attachments to EmailMessage in addition to attachments provided by EmailTemplate.

Sending an Email with a Template

When modeling your app in Studio Pro, use the SendEmailWithTemplate Java action to send an email from a template. The input parameters are the following:

  • Data Object – This is an entity object from which you want to extract the placeholder tokens. If you want to retrieve from multiple objects, create a non-persistable entity.
  • EmailAccount – This is an email account consisting of the outgoing email configuration.
  • EmailTemplate – This is an email template from which an EmailMessage object is created and sent.
  • Queued – When true, the email message is stored in the EmailMessage entity with its status as Queued. In this case, you can send it later using a scheduled event. You can use the SE_SendQueuedEmails microflow to create scheduled events. You can also create a task queue and run the microflow in that task queue to minimize system resource usage. Using a task queue, you can set the number of threads, node or cluster-wide scope, time intervals, and other parameters.

Refer to the sample microflow Sample_ACT_SendEmailWithTemplate. To use To, CC, or BCC during runtime, change the EmailTemplate object and set the desired values for the attributes, then pass the same EmailTemplate object as a parameter to the Java action.

Exporting Email Template

Email connector now supports the export and import of email templates. This feature reduces the manual work required to recreate templates in various development, acceptance, and/or production environments.

Select the email template that you want to export and click Export. The exported XML file is named with the email template name and a datetime stamp and is downloaded directly to your default download folder. The image below shows the downloaded XML file after the email template export.

Importing Email Template

You can import the exported email template into the same or a different deployment environment. Click Import to start importing the email template. A pop-up window will appear, allowing you to browse for the template file (.xml) to import. Click Import Template to complete the email template import process. After successfully importing the email template, you will receive a status message notification.

Signed and Encrypted Emails

You can optionally configure a digital signature and email encryption while the module is running. A digital signature allows the recipient to verify the authenticity of the sender, while encryption ensures the message content is securely scrambled and can only be read with the correct decryption key.

Digital Signing

Digitally signed emails support only PKCS#12 certificates.

Email Encryption

Encryption for emails using the Email connector includes the following:

  • Support for LDAP servers for sending encrypted emails
  • Two options for authentication methods: Simple and No (anonymous)
  • Support for SSL/TLS and non-SSL connection types
  • While encrypting email, the recipient's public certificate will be searched for on the base DN

Subscribing to Incoming Email

When modeling your app in Studio Pro, call the SubscribeToIncomingEmail Java action to subscribe to incoming email from an account.

The input parameters are the following:

  • EmailAccount – This is an email account consisting of the incoming email configuration.

  • onNewEmailReceivedMicroflow – This is a microflow that is triggered when new email is received from the server. You can process the list of emails according to your needs.

  • onSubscriptionStateChangedMicroflow – This is a microflow that is triggered when the subscription state is changed. The state can be any of the following values:

    • SUBSCRIPTIONFAILED
    • CONNECTIONTOSERVERLOST
    • CONNECTIONRETRYEXHAUSTED

Enabling Subscription in Email Settings

For some use cases, like triggering actions when a new email is received, you need to enable the subscription to new emails in the email settings as well as in the subscription microflow documented in Subscribing to Incoming Email.

Additional Considerations

When subscribing to incoming email, keep the following additional considerations in mind:

  • It is recommended to unsubscribe from any incoming email before subscribing to incoming email. This helps prevent the application from having duplicate subscriptions for a single email account. The complete subscription flow is shown in the SUB_EmailAccount_SubscribeForEmailNotification microflow.

  • The subscription to new emails works only if the email account is configured with IMAP/S protocol and if the email server supports notifications. The subscription will end if the app is stopped. To subscribe again between app restarts, register the Sample_ASU_SubscribeForEmailNotification microflow in the After Startup option.

Unsubscribing from Incoming Email

When modeling your app in Studio Pro, use the UnsubscribeFromIncomingEmail Java action. When used with account parameters, the provided account will be unsubscribed from incoming email.

There is one input parameter:

  • EmailAccount – email account consisting of the incoming email configuration

Configuring Microsoft Entra ID OAuth 2.0

You can configure your account to authenticate with Microsoft Entra ID OAuth 2.0. Multiple OAuth 2.0 providers can be configured per app.

If no email accounts are configured, you can create a new OAuth configuration from the Add Email Account wizard by selecting Use Microsoft Entra ID. Otherwise, select OAuth Configurations to add, delete, and edit OAuth configurations, as described in the next section.

OAuth Provider Configuration Details

To configure an OAuth provider for the authentication code flow, provide the following details:

  • Client ID – Found in the Microsoft Entra ID after registering your app
  • Client Secret – Available in the Microsoft Entra ID once the app is registered
  • Callback Path – Any string value; the system will auto-generate the callback URL based on this path
  • Callback URL – Known as the Redirect URI in the Microsoft Entra ID; this is the URL where the OAuth provider redirects after providing the authorization code

To configure an OAuth provider for the client credentials grant flow, provide the following details, which are available on the Microsoft Entra ID once you have registered your app:

  • Client ID
  • Client Secret
  • Tenant ID

With Email Connector version 5.2.0 and newer, you can send emails using a client credentials flow.

Settings in the Microsoft Entra ID (Authentication Code Flow)

To register your app on the Microsoft Entra ID, follow Microsoft's tutorial Register an app with Microsoft Entra ID. As mentioned above in OAuth Provider Configuration Details, make sure to set the Redirect URI as the Callback URL.

This connector contains functionality for sending and receiving emails, so during the OAuth process, the connector will ask for permissions for sending and receiving emails.

On the Microsoft Entra ID, ensure you have the following permissions enabled under the API permissions tab on the sidebar:

Send Emails
Permission Name Description
SMTP.Send Send emails from mailboxes using SMTP AUTH.
User.Read Sign in and read user profile (required for authentication).
openid Sign users in (required for OAuth/OpenID Connect).
offline_access Maintain access to data you have given it access to (for refresh tokens).
profile View users' basic profile (often used during sign-in).
email View users' email address (optional but helpful).
Receive Emails
Permission Name Description
IMAP.AccessAsUser.All Read and write access to mailboxes via IMAP.
POP.AccessAsUser.All Read and write access to mailboxes via POP.
User.Read Sign in and read user profile (required for authentication).
openid Sign users in (required for OAuth/OpenID Connect).
offline_access Maintain access to data you have given it access to (for refresh tokens).
profile View users' basic profile (often used during sign-in).
email View users' email address (optional but helpful).

Settings in the Microsoft Entra ID (Client Credentials Flow)

To register your app in the Microsoft Entra ID portal, follow Microsoft's Register an app with Microsoft Entra ID.

This connector contains functionality for sending and receiving emails. APIs related to Office 365 Exchange Online need to be given permission along with admin consent.

On the Microsoft Entra ID, ensure you have the following permissions enabled under API permissions tab on the sidebar:

Send Emails (Application Permissions)
Permission Name Type Description
SMTP.SendAsApp Application Sending email via SMTP AUTH.
Receive Emails (Application Permissions)
Permission Name Type Description
IMAP.AccessAsApp Application Read and write access to all mailboxes via IMAP.
POP.AccessAsApp Application Read and write access to all mailboxes via POP.

Admin status is given on the added API permissions. The tenant admin must register the Microsoft Entra ID application's service principal in Exchange via Exchange Online PowerShell, as described in Register service principals in Exchange.

Queuing Emails

Emails can be stored in the Queued folder to be sent later. You can manually send them at any time. If sending fails, the connector will automatically retry until it reaches the Max. send attempts limit. Once this limit is reached, any unsent emails are moved from the Queued tab to the Failed tab on the overview page.

Troubleshooting

Sending or Receiving Email

If you have issues sending or receiving emails, first check the Error logs in Account Settings and the logs in Studio Pro. If an email you sent does not appear in your app and there is nothing in the logs, the problem is not with the connector.

Gmail Accounts

Gmail no longer supports basic authentication (usernames and passwords), but you may still be able to set up an account in the Email connector by doing the following:

  1. Read Less secure apps & your Google Account and turn off the Less secure app access setting in your Google account.
  2. Set up an app password to sign in to the Email connector. For more information, see Sign in with app passwords.

Adding OAuth 2.0 Configuration to an App with Basic Authentication

If you already have an email account configured using basic authentication in your app, and you want to use OAuth 2.0 authentication without removing that email account, do the following:

  1. On the overview page, click OAuth Configurations and add a new configuration. For more information, see OAuth Provider Configuration Details.
  2. For the desired email account, set the isOAuthUsed attribute of the EmailAccount entity to True.
  3. Associate the email account with your newly created OAuth provider.
  4. Navigate to the overview page, click Manage Accounts, and select the account.
  5. Go to the Server Settings tab in Account Settings and select Re-authenticate Access.

Deprecation of Basic authentication in Microsoft Exchange Online

As of October 1, 2022, Microsoft has deprecated Basic Authentication, and it is no longer supported in Exchange Online, promoting Modern Authentication (OAuth 2.0) for enhanced security. From that date, Microsoft started disabling Basic Authentication for the following protocols: Outlook, EWS, RPS, POP, IMAP, and EAS.

Deploying to On-Premises Cloud Environments

When deploying on premises running Microsoft Windows, you need to add a rule for a URL redirect. Add the following rule to the web.config file where the on-premises application is installed:

<rule name="mxecoh">
   <match url="^(mxecoh/)(.*)" />
   <action type="Rewrite" url="http://localhost:8080/{R:1}{R:2}" />
</rule>

For more information, see the Reverse Proxy Inbound Rules section of How to Deploy Mendix on Microsoft Windows.

Configuring Local Email Clients

Configuring local clients, such as Papercut, is supported. If you are using a tool like Papercut, do the following:

  1. Follow the steps for adding an email account.
  2. Continue with manual configuration in the wizard. (Automatic configuration does not work for local clients.)
  3. Select the Send emails checkbox.
  4. Select SMTP for the Protocol, and enter localhost for the Server host. Enter the Server port number (for example, 25).
  5. Enter a random email ID and password on the login screen, and it will be configured.

Adding Attachments

Normal Attachment

To add attachments to the email message, do the following:

  1. Create an Attachment entity. The Attachment entity extends the FileDocument entity by making it usable in all the places where the FileDocument entity is required.

  2. Set the Attachment_EmailMessage association.

Inline Attachment

To add inline attachments to an email message, you can use the Rich text editor to insert an image (or images) into the email body. You can also insert inline attachments by using a microflow. To use a microflow, follow these steps:

  1. Create an EmailMessage with the Content property set as seen below:

    'before inline image<br><img src="cid:mxcid:test.png" width="530" height="110"><br>after inline image'
  2. Specify the image's tag source using the cid:mxcid prefix before the source file to have the image added as inline image.

  3. Create the attachment with the Position attribute set to ENUM_AttachmentPosition.Inline.

  4. Associate the attachment with EmailMessage. You can then send the email using the SUB_SendEmail microflow.

Page Styling

If the Email connector page styling is affected as you select and view email messages, it likely due to errors in the email message CSS. To resolve the errors, turn on Sanitize email to prevent XSS attacks in Account Settings.

Importing Emails with Long Attachment Names

Some email clients (for example, Gmail) break down the name of attached files if it is longer than a specific value, and add the file name in the Content Type for an attachment. This can cause an error while fetching or importing emails with long attachment names. For example: "ERROR - Email_Connector: Attribute 'Email_Connector.Attachment.attachmentContentType' has a maximum length of 200, tried setting a value of length xxx.". This issue is resolved in version 5.3.0 of the Email Connector.

Known Issues

Widgets

If you already have the included widgets in your app and they are not up to date, you may get a "Some widgets cannot be read" error when trying to run locally.

Consistency Error

You may get a consistency error when importing the Email Connector module in Mendix 10.1 or above that states "No argument has been selected for parameter "Token" and no default is available". This can be resolved by double-clicking the error, which takes you to the snippet SNIP_EmailTemplate_NewEdit. Double-click the Edit [default] button, then in the Events field under Page settings, click Edit. Once the Page Settings dialog box opens, click OK, as shown in the image below. The error should resolve.

Duplicate Mx Model Reflection Objects in Email Template

The Email Template export/import functionality introduced in EC v5.8.0 had a bug, which was subsequently fixed in v5.9.0. If you exported and imported Email templates using EC v5.8.0, you may see duplicate records in the placeholder entity drop-down, as shown below.

To clean up these duplicate Mx Reflection records, a microflow is delivered as part of EC v5.9.2. As the clean up microflow (DEL_DuplicateMxReflectionObjects) deletes database records from certain tables, it is strongly advised to complete a full DB backup before proceeding with the steps below. At a minimum, the following 3 tables must be fully backed up before starting.

  1. MxObjectMember
  2. MxObjectReference
  3. MxObjectType

To perform the clean up, follow these steps:

  1. Call the DEL_DuplicateMxReflectionObjects microflow from a page using the Call microflow button. Preferably, an Admin user should trigger this microflow. This is a one-time activity. This microflow identifies the duplicate records in the backend and removes them. Upon completion, you see a pop-up dialog stating that the process has been completed. You can see how many records were removed from respective table in the Console log, as shown below.

  2. After the cleanup, remove the Call microflow button from the page so the microflow cannot be triggered again.