Cannot connect to server. (Unable to connect)

I can’t get K-9 Mail to work with either of my email accounts, neither iCloud nor Gmail.

I have followed Apple’s instructions here:

This identical configuration for iCloud works for me in Thunderbird, but not K-9.
Depending on whether I select SSL/TLS or STARTTLS in K-9, I receive either the titular message or “Setup could not finish Username or password incorrect. (unmatch quote)”.

For my Gmail, a similar message. “Setup could not finish Username or password incorrect. (invalid credentials (Failure))”

For adding a Gmail account, see How do I add a Gmail account? and maybe How do I add a Google Workspace account?

Thanks, I was able to get my Gmail working, but my iCloud email still eludes me.

Any ideas? No combination of settings works.

The iCloud Mail documentation states that you need to generate an app-specific password. Did you do that? Are you using the app-specific password with K-9 Mail?