File | Date | Author | Commit |
---|---|---|---|
mta-sts | 2024-11-15 |
![]() |
[cc68e0] Initial version |
LICENSE | 2024-11-14 |
![]() |
[906475] Initial commit |
README.md | 2024-11-15 |
![]() |
[2e5222] Update README.md |
mta-sts.txt | 2024-11-15 |
![]() |
[331a7b] Example output |
Server-wide dynamically created mta-sts.txt using PHP.
https://domain.tld/.well-known/mta-sts.txt
For Apache and Nginx.
(Based on Ubuntu 24.04 server, but should work on older versions and other distro's too)
Why you ask?
SMTP connections for email are more secure when the sending server supports MTA-STS and the receiving server has a MTA-STS policy in "enforced" mode.
Receiving mail: When you turn on MTA-STS for your domain, you request external mail servers to send messages to your domain only when the SMTP connection is both:
- Authenticated with a valid public certificate
- Encrypted with TLS 1.2 or higher
Mail servers that support MTA-STS will send messages to your domain only over connections that have both authentication and encryption.
Features:
- Fields "mode" and "max_age" according to RFC8461 can be configured
- If values are invalid then redirect to http://<(sub.)domain.tld>/
- Check if visited URL is HTTPS, if not then redirect to HTTPS
- Check if visited URL starts with "mta-sts.", if not then redirect to http://<(sub.)domain.tld>/
- Check if (sub)domain "<(sub.)domain.tld>" has "_mta-sts.<(sub.)domain.tld>" TXT record in DNS, if not then redirect to http://<(sub.)domain.tld>/
- Check if (sub)domain "<(sub.)domain.tld>" has MX record(s) in DNS, if none then redirect to http://<(sub.)domain.tld>/
- Generate mta-sts.txt in which MX is sorted by weight, if weight is equal then by alphabet
(for any other location you need to alter apache.conf or nginx.conf)
cp /var/www/mta-sts/conf/apache.conf /etc/apache2/conf-available/mta-sts.conf
Or create a symlink in /etc/apache2/conf-available
ln -s /var/www/mta-sts/conf/apache.conf /etc/apache2/conf-available/mta-sts.conf
Check PHP handler and change if necessary
Enable securitytxt.conf in Apache
a2enconf mta-sts
systemctl reload apache2
cp /var/www/mta-sts/conf/nginx.conf /etc/nginx/snippets/mta-sts.conf
Or create a symlink in /etc/nginx/snippets
ln -s /var/www/mta-sts/conf/nginx.conf /etc/nginx/snippets/mta-sts.conf
Check PHP handler and change if necessary
Reload Nginx
systemctl reload nginx
Add below to every website's vhost configuration.
If you use a management system like ISPConfig, Plesk etc. than add below to the vhost config that is used when adding or altering a website.
Resync all websites after.
RewriteEngine on
RewriteOptions Inherit
include /etc/nginx/snippets/mta-sts.conf;
version: STSv1
mode: enforce
mx: mx1.domain.tld
mx: mx2.domain.tld
max_age: 604800