Can’t add email accounts in macOS (stuck on final step)

When I tried to add an Exchange account (but it seemed to affect IMAP accounts too) in macOS (I was running High Sierra, but it affects other versions too), from either the Internet Accounts preference pane or Mail.app, it would let would let me add an account right until the final step where it asks what kind of services you want enabled on the account, then the Done/Next button just does nothing. You might get a throbber for a second, but it subsides and does nothing.

There’s a lot of somewhat convulted steps posted on the internet, but the simplest is to just reset your keychain from the Keychain Access application (Application Menu->Preferences, it’s one of the options there) and reboot. You’ll have to enter your passwords again (including iCloud), but I had no trouble adding mail accounts after that.