A mail setup for server alerts always ends up needing a password somewhere. The default place, a plain line in a config file, is the one the msmtp manual itself calls not a good idea. The alternative takes one line.
passwordeval gpg2 --no-tty -q -d ~/.msmtp-password.gpg
Put that in the account section of ~/.msmtprc, next to auth on and user. The manual says msmtp uses the output of the command on standard output as the password. The example comes from the manual and decrypts a GnuPG file, but any command that prints the password works, such as a keyring query.
The manual recommends two ways to store the password: the system key ring, or an encrypted file together with passwordeval. The key ring route for Gnome uses secret-tool and for macOS the Keychain. If you do put a password in the config with password, the manual says to make sure only you can read the file.
Two details from the documentation. The command must not touch standard input, and if in doubt you should append < /dev/null. And you can check what msmtp will use without sending anything:
msmtp --pretend --account=alerts
-P (--pretend) prints the configuration settings that would be used and does nothing else. The manual says an asterisk is printed instead of the password.
The caveat is the unattended case. In the manual’s example gpg-agent asks for the decryption password once, which doesn’t suit an alert script that runs when nobody is at the keyboard. Pick the key ring or another command that can answer without a prompt for those. This follows the manual and was not run, because msmtp was not installed here.
Further reading: msmtp manual