Unable to store credential due to error -25291 Requested By: Mail
Restarting this thread https://discussions.apple.com/thread/8597999?login=true
I recently had this problem crop up. Mojave 10.14.6. Connecting to my own personal IMAP server that worked perfectly fine via webmail login. After several hours of fiddling I determined that it seems to be caused by issues with stale (or corrupt? or not-synced?) iCloud Keychain entries. I went to system prefs -> iCloud, unchecked "Keychain", closed prefs, reopened, checked "keychain". Shortly thereafter my iCloud Keychain re-synced to my Mac and Mail started working again.
MacBook Pro 15″, macOS 10.14