Even more email security with MTA-STS and DANE!

Lesedauer 10 Minuten

SPF, DKIM, and DMARC are now widely established as authentication mechanisms for email communication—although there is still some ground to make up. These mechanisms should therefore be considered the absolute foundation when it comes to email security. Conversely, it is, at the very least, grossly negligent not to have them set up by now.

Regardless, there are additional mechanisms called MTA-STS and DANE designed to improve email security. These are primarily aimed at countering active attempts to compromise the communication itself, such as eavesdropping attacks. Microsoft has supported both mechanisms with Exchange Online for some time now (MTA-STS: February 2, 2022; DANE: March 2022 (inbound), October 2024 (outbound)).

However, configuring these mechanisms is not quite as straightforward as with SPF, DKIM, and DMARC. Furthermore, certain prerequisites must be met, which are not available in every environment. This article clearly illustrates the respective setup procedures and what to keep in mind during the process.

Description of the mechanisms

The following chapters briefly describe what the abbreviations mean and the purpose of the mechanisms. Generally speaking, they expand upon the mechanisms for authenticating transport paths and the remote party's certificate. The two mechanisms can be used independently or in combination.

MTA-STS

The abbreviation MTA-STS stands for Mail Transfer Agent-Strict Transport Security. This standard is designed to ensure that TLS encryption is negotiated without exception for communication between two email servers.

In addition, MTA-STS allows the sender to validate the recipient’s certificate. If the certificate is invalid, email delivery is denied. Exchange Online supports MTA-STS for both incoming and outgoing email communication.

For outbound communication, Exchange Online respects the policy in place on the receiving end (if any). The use of MTA-STS can also be specifically disabled via a dedicated outbound connector, if necessary (see the chapter “Handling TLS encryption, MTA-STS and DANE in specific scenarios”).

DANE

The abbreviation DANE stands for DNS-based Authentication of Named Entities. This standard enables the verification of a system’s TLS certificate (such as that of the recipient system) using DNS in conjunction with the security extensions of DNSSEC.

It is used not only for email communication but also for accessing websites via HTTPS. In this process, an entry is stored in the DNS, which can be used to validate the certificate’s validity independently of the certificate authority used. If validation fails, no TLS connection is established.

DANE is supported in Exchange Online for both incoming and outgoing traffic.

Prerequisites

For SPF, DKIM, and DMARC, you basically just need to configure additional entries in the DNS zone and set a few settings. For MTA-STS and DANE, however, there are more stringent requirements, which are explained below.

MTA-STS

In addition to DNS entries, a text file is required that must be accessible via a company website. The URL for the text file is predefined by default and is https://mta-sts.<domain>.<suffix>/.well-known/mta-sts.txt, e.g., https://mta-sts.zava.com/.well-known/mta-sts.txt. This text file defines the company’s policy for the assigned email domain. The text file looks like this:

version: STSv1
mode: testing (oder enforce oder none)
mx: mail.example.com
mx: *.mail.example.com
max_age: 604800
BAT (Batchfile)

There are several options for hosting the text file:

  1. The company has a website. The text file is also hosted on the web server.
  2. The website should not be used for this purpose, or there is no website available. A separate system is set up for this purpose.

In the related Learn article, Microsoft lists two options for this: Azure Functions and Azure Static Web App. The latter option is recommended and is also free. Accordingly, the setup process will be described below using an Azure Static Web App (prerequisite: the company must have an Azure subscription, which is also free). You can find out how to get one here: The Microsoft Cloud Transformation | Part 1: Once upon a time... it started with an Azure subscription).

A (free) GitHub account is also required to deploy the code for the web app (Azure DevOps would also be an option if the company already has it).

DANE

If DANE is to be used in addition to or as an alternative to DNSSEC, you must verify whether the provider for the public DNS zone supports signing via DNSSEC. For some providers, this is an additional feature that incurs a fee (e.g., IONOS, United Domains, etc.). DANE cannot be implemented without DNSSEC. Aside from that, there are no other requirements.

Configuration

Setup TLS reports

Before setting up MTA-STS and/or DANE, an entry for TLS reports must be added to the public DNS zone. Similar to DMARC, this entry specifies the recipient address to which reports should be sent if problems arise during TLS negotiation. This makes it possible to identify potential issues during a test phase and, ideally, resolve them in advance.

The reports can be sent via traditional email and/or as a POST request to an HTTPS endpoint:

NameTypeContent
_smtp._tlsTXTv=TLSRPTv1; rua=mailto:<E-Mail-Adresse>,https://<HTTPS-Endpunkt>;

If only one of the options is to be used, the unnecessary part can be removed from the content accordingly.

MTA-STS

The following chapters describe all the steps for deploying MTA-STS via an Azure Static Web App.

Setup a GitHub account and provision the structure

A GitHub account is required to deploy the code for the web app. You can set one up for free at any time via the official website: Sign up for GitHub · GitHub

After the initial setup, you must create a repository for each DNS zone. Technically, a single repository would suffice, but I prefer a clear separation by function. This also allows the policy to be managed individually for each domain. You can name the repository whatever you like, but the name should reflect the repository’s purpose. For example: mta-sts-zava-com

Inside the repository, create the following folder structure: home/.well-known

In the home folder, create an index.html file with the following content:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>MTA-STS</title>
</head>

<body>
<h1>MTA-STS Static Website index</h1>
</body>

</html>
HTML

In the .well-known folder, create a file named mta-sts.txt with the following content:

version: STSv1
mode: testing
mx: <your MX endpoint, e.g., *.mail.protection.outlook.com>
max_age: 86400
HTML

This completes the preparations on GitHub. If additional domains are to be protected with MTA-STS, additional repositories should be created following the same procedure.

Setup web app in Azure

Now, the static web app can be set up in Azure as follows:

  • Go to the Azure Marketplace: Marketplace - Microsoft Azure
  • Enter static web app in the search field and select the Microsoft product from the results
  • Click Create
  • Create a new resource group or select an existing one
  • Assign an appropriate name (e.g., the same name as the GitHub repository)
  • Select Free as the hosting plan (this is sufficient for the intended purpose)
  • In the deployment details, make sure GitHub is selected, and sign in with the GitHub account you created earlier using the button below
  • Select the appropriate repository from the drop-down menus below
  • On the Deployment Configuration tab, select the GitHub option
  • On the Advanced tab, select the appropriate region
  • Switch to the Review + Create tab and click Create

The creation process should not take long. After deployment, you must enter the URL for access. To do this, follow these steps:

  • Open the newly created resource
  • Go to Settings > Custom Domains
  • At the top, select the option + Add > Custom Domain in Another DNS
  • In the new menu, enter the domain in the following format: mta-sts.., e.g., mta-sts.zava.com

This automatically generates and assigns a suitable certificate in the background for HTTPS access to the website.

The domain must then be validated via a TXT record (important: do not use the CNAME record here, as it will be used for another purpose later). After successful validation, a redirect can then be configured using a CNAME record:

NameRefers to
mta-sts<Automatically generated URL for the static web app, ending in ...azurestaticapps.net

The MTA-STS policy should then be accessible via the URL https://mta-sts../.well-known/mta-sts.txt (once the name servers have processed the records).

Setup DNS record

Next, the required DNS record can be added to the public DNS zone. This record indicates to senders that an MTA-STS policy exists for the domain and defines a unique version ID for the policy. This ID must be updated whenever the policy is changed (e.g., by adjusting it to the current date).

NameTypeContent
_mta-stsTXTv=STSv1; id=<yyyymmddhh00Z>;

In this example, the ID corresponds to the combined date and current time. There are no specific requirements to follow here. The ID simply defines a unique value for the policy. Accordingly, the specified dates do not necessarily have to match the current date. The format can be quickly created using the following PowerShell command—the variable $STSRecord then contains the content to be configured:

$STSRecord = 'v=STSv1; id=' + (Get-Date -Format yyyymmddhh00) + 'Z;'
PowerShell

Enable enforcement in policy

Once all prerequisites have been configured, the policy can be enabled. To do this, change the mode in the text file from testing to enforce.

DANE

If DNSSEC has been enabled for the public DNS zone, the configuration can be performed as described below.

Reduce the MX TTL, adjust the MTA-STS policy

First, the maximum validity of the existing MX record must be reduced (to the shortest possible duration, but no less than 30 seconds). This ensures that, in the event of an error, the system can quickly revert to the original configuration. You must then wait for the previous TTL to expire (e.g., 1 hour if the value was previously 3600).

If MTA-STS is enabled for the domain, the policy must be changed to “testing” mode, and the ID in the DNS record must be updated accordingly. Here, too, you must wait for the TTL to expire.

Enable DNSSEC in Exchange Online, adjust the MTA-STS policy

Next, you must enable DNSSEC for the domain you want to protect in Exchange Online. You must use PowerShell to do this, since there is no option for it in the Admin Center:

# Install needed module, if not installed yet
if (!(Get-InstalledModule ExchangeOnlineManagement)){Install-Module ExchangeOnlineManagement -Scope CurrentUser}

# Choose domain to be protected
$DomainName = (Get-AcceptedDomain | Select-Object DomainName | Out-GridView -Title 'Please choose domain to be protected' -OutputMode:Single).DomainName

# Enable DNSSEC
Enable-DnssecForVerifiedDomain -DomainName $DomainName
PowerShell

Once the process has been successfully completed, a new MX record is generated. This must be added as an additional MX record in the public DNS zone. Important: Use the lowest possible TTL, but set a higher priority than the existing record.

If MTA-STS is enabled for the domain, the stored MX record must also be adjusted accordingly. Likewise, the ID in the DNS record must be updated.

Functional test

You need to test whether the new MX endpoint is working as expected. You can use Microsoft's Remote Connectivity Analyzer for this: Microsoft Remote Connectivity Analyzer: Test Input

Switch MX records

Provided that the new MX endpoint has been successfully tested, the incoming message flow can be switched to the new endpoint as follows:

  • Adjust the priorities so that the new MX record has a lower value than the previous record. This makes the new MX endpoint the preferred endpoint.
  • Delete the previous MX record.

From this point on, only the new MX endpoint will be used for incoming emails. The endpoint also functions independently of whether DANE or MTA-STS is enabled.

Enable DANE, adjust the MTA-STS policy

Next, you can enable DANE for incoming emails for the domain you want to protect in Microsoft 365. You'll need to use PowerShell to do this, since there is no option for it in the Admin Center:

# Install needed module, if not installed yet
if (!(Get-InstalledModule ExchangeOnlineManagement)){Install-Module ExchangeOnlineManagement -Scope CurrentUser}

# Choose domain to be protected
$DomainName = (Get-AcceptedDomain | Select-Object DomainName | Out-GridView -Title 'Please choose domain to be protected' -OutputMode:Single).DomainName

# Enable DANE
Enable-SmtpDaneInbound -DomainName $DomainName
PowerShell

After waiting approximately 15–30 minutes, you can verify whether the corresponding TLSA entries have been generated in Exchange Online. You can use the Remote Connectivity Analyzer for this: Microsoft Remote Connectivity Analyzer: Test Input

Note

When running the test, it is possible that not all entries can be successfully validated. However, this is not an error or a problem; rather, it is expected behavior. Only one entry needs to be successfully validated to ensure that the functionality works as intended.

If MTA-STS is active for the domain, the policy can be set back to enforce after a successful test. The ID in the DNS record must also be updated.

Warning

In my tests, I encountered problems with email delivery after changing the setting to enforce. As shown in Microsoft's official example, I had configured the MX record with a wildcard. However, this does not seem to work properly, as emails are rejected with this configuration due to a detected mismatch.

Therefore, the recommendation is to configure the MX record(s) using the original format rather than a wildcard entry, and to add additional MX records if necessary. Multiple MX entries can be added without any issues.

Handling of TLS encryption, MTA-STS and DANE in specific scenarios

By default, Exchange Online uses opportunistic negotiation for outgoing emails. This means that if the recipient’s server does not support TLS, MTA-STS, and/or DANE, it will switch to a weaker connection method. However, this behavior can be specifically controlled on a per-recipient-domain basis by creating an appropriate connector. The parameters can only be set using PowerShell:

# Install needed module, if not installed yet
if (!(Get-InstalledModule ExchangeOnlineManagement)){Install-Module ExchangeOnlineManagement -Scope CurrentUser}

# TlsSettings = Enforce TLS encryption, optionally validate certificate and or domain additionally
# MtaStsMode = Disable MTA-STS, if needed
# SmtpDaneMode = Disable or enforce DANE, if needed

# A) Create new connector
New-OutboundConnector -Name '<name, max. 64 characters>' -RecipientDomains '<recipient domain(s), comma-separated>'`
 -TlsSettings '<EncryptionOnly|CertificateValidation|DomainValidation>'`
 -MtaStsMode '<Opportunistic|None>'`
 -SmtpDaneMode '<Opportunistic|Mandatory|None>' 

# B) Customize existing connector
Set-OutboundConnector -Name '<name, max. 64 characters>'`
 -TlsSettings '<EncryptionOnly|CertificateValidation|DomainValidation>'`
 -MtaStsMode '<Opportunistic|None>'`
 -SmtpDaneMode '<Opportunistic|Mandatory|None>' 
PowerShell

I've also posted a more comprehensive script in my script nest that makes the setup process a little easier.

Outlook: BIMI

There is another standard designed to further enhance communication security. This standard is called BIMI (Brand Indicators for Message Identification).

With BIMI, your organization’s logo is added to outgoing emails. In email apps that support BIMI, the logo is then displayed alongside the email in the inbox. The logo is verified by a third-party provider to ensure its authenticity. Accordingly, certain requirements apply to the logo (e.g., Verified Mark Certificate or Common Mark Certificate).

However, BIMI is currently supported by only a very small number of providers, such as Google, Yahoo Mail, and Apple Mail. Microsoft supports BIMI only for emails sent from Dynamics 365 Customer Insights, not for emails from Exchange Online. Additionally, Outlook does not support BIMI for incoming emails.

Microsoft has not yet announced any plans regarding whether or when BIMI will be supported for Exchange Online. However, this will most likely not happen until providers such as Google begin to push for its adoption.

Conclusion

Setting up MTA-STS and/or DANE is definitely more complex than setting up SPF, DKIM, and DMARC. However, it is an essential step toward moving away from opportunistic TLS negotiation between email systems and toward end-to-end encryption of transport paths. It is therefore the next logical step after setting up SPF, DKIM, and DMARC and should be tackled promptly to help drive adoption!



Liked this article? Share it!