msmtp permission denied errors: disable apparmor!

2020-08-15

If you see "permission denied" errors with msmtp, please disable AppArmor to see if this fixes the problem: sudo aa-disable /etc/apparmor.d/usr.bin.msmtp
More information: unfortunately Debian and Ubuntu provide an AppArmor profile for msmtp that frequently breaks functionality, and in ways that are very hard to debug. Until they fix that profile, I can only recommend disabling it whenever you see a "permission denied" error that has no apparent reason.
The latest example affects OAUTH2 authentication. Thanks to Github user marcelolaia for figuring this out!

Update 2021-09-13:The Debian package for msmtp 1.8.15 now disables the AppArmor profile by default. The profile has received many improvements in the mean time, so it might make sense to enable it depending on your use case. Many thanks to the Debian contributors for their work!