Setting Fastmail DNS records for Cloudflare

Search for a command to run...

No comments yet. Be the first to comment.
Phew, that was a lot. I'm always surprised how simple solutions contain so much detail and nuance when I try to explain them. I hope I conveyed the message that A-Frame simplifies code within a module or class by separating the infrastructure compone...

No architecture is complete without an easy way to test the functionality. My recommended strategy is to use two types of tests: unit and integration. As far as test setup goes, there is no clear winner for a test framework. xUnit.NET, NUnit and the ...

The examples in the previous posts seem really nice for simple scenarios. How do I approach more advanced use cases? The big scenarios are: I need multiple pieces of data from different sources I need to perform an infrastructure call in the middle...

I’ve shown how I write code using the A-Frame architecture without help. Yet I find a library or framework very convenient when using advanced techniques. Wolverine is at its core a messaging framework, but goes well beyond that. It has an in-memory ...

Now the expected structure is clear, let's take a look at the code. I will start with a minimal API implementation to demonstrate that there is no need for a framework to implement this architecture. I do know of a framework that makes A-Frame effort...

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. 😁