Skip to content

Instantly share code, notes, and snippets.

@dotysan
Created April 29, 2022 19:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dotysan/5ca9bee46425d1b3af47319801e6692c to your computer and use it in GitHub Desktop.
Save dotysan/5ca9bee46425d1b3af47319801e6692c to your computer and use it in GitHub Desktop.
CloudFlare Worker for MTA-STS policy
const mode= 'testing';
//const mode= 'enforce';
const max_age= 604800; // 1 week
const mx_list = [
'aspmx.l.google.com'
,'aspmx2.googlemail.com'
,'aspmx3.googlemail.com'
,'aspmx4.googlemail.com'
,'aspmx5.googlemail.com'
,'alt1.aspmx.l.google.com'
,'alt2.aspmx.l.google.com'
];
const sts= `version: STSv1
mode: ${mode}
${mx_list.map(i=> 'mx: '+i).join('\n')}
max_age: ${max_age}`;
addEventListener('fetch', evt=> {
return evt.respondWith(new Response(sts));
});
@dotysan
Copy link
Author

dotysan commented Jul 20, 2023

Don't forget to add the route to this worker: https://[example.com]/.well-known/mta-sts.txt

@mamiu
Copy link

mamiu commented Aug 5, 2023

Thanks a lot @dotysan!

I had to adjust the mx_list slightly:

const mode = 'testing';
// const mode = 'enforce';
const max_age = 604800; // 1 week
const mx_list = [
   'aspmx.l.google.com',
   'alt1.aspmx.l.google.com',
   'alt2.aspmx.l.google.com',
   'alt3.aspmx.l.google.com',
   'alt4.aspmx.l.google.com'
];

const sts = `version: STSv1
mode: ${mode}
${mx_list.map(i=> 'mx: '+i).join('\n')}
max_age: ${max_age}`;

addEventListener('fetch', evt=> {
  return evt.respondWith(new Response(sts));
});

And add an A record to be able to route the traffic to this worker:

  • Type: A
  • Name: mta-sts
  • IPv4 address: 192.0.2.1
  • Proxy status: On (this is important!)
  • TTL: Auto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment