Recently I switched from Googles Workspaces to Fastmail as my mail provider. Not only am I paying less, I'm getting more in return. I love the +notation alternative and that any, not-specified, email address gets dropped into my inbox. No more setting up info@mydomain.com, it just gets delivered to me. Setting all those DNS records is a bit time consuming, error prone and just annoying. So, scripting to the rescue.
Since I've been enjoying F# immensely the last few months (I'll probably blog some more about that in the future), I figured I'd write an F# script to create these DNS records automatically. And good news, I kept all secret bits out of it so I can share it with you, my dearest reader!
The script can be found in a public Github Gist. I won't go over every detail of the script, but you can see that I create a list of DNS records, serialise them and then post them to Cloudflare.
How do you use the script? Copy the script to a file ending with .fsx
. Make sure you have at least dotnet 5 installed. Then execute the following line
dotnet fsi [path-to-script] [domain] [cloudflare-auth-key]
Example: dotnet fsi .\set-fastmail-dns-in-cloudflare.fsx kenbonny.net 00000000000-ABCdef
The cloudflare-auth-key
can be found in your Cloudflare Dashboard. They have a nice guide on how to create a token.
Fastmail provided an easy list of all the DNS records that should be set to make everything work.
Keep one thing in mind: the Cloudflare API documentation is not up to date when it comes to creating SRV DNS records. Other DNS records require a general JSON structure:
{
"type": "CNAME",
"name": "fm1._domainkey.domain.com",
"content": "fm1.domain.com.dkim.fmhosted.com",
"ttl": 1,
"priority": null,
"proxied": false
}
An SRV DNS record needs a specific JSON structure:
{
"type": "SRV",
"data": {
"service": "_caldavs",
"proto": "_tcp",
"name": "domain.com",
"priority": 0,
"weight": 1,
"port": 443,
"target": "caldav.fastmail.com"
}
}
Hopefully this saves somebody some setup headache when configuring Fastmail on Cloudflare. Including me, when I add more domains to my account. ๐