Note: Also, additional msmtp keys can be set up (TLS options etc.); the list of all msmtp keys can be looked up using the console command:
msmtp --help.

Restart Nagios to apply settings:

service nagios restart

In other words, in the Nagios configuration file we basically change MTA from mail to msmtp with keys and slightly modify the message text. Since msmtp has no Subject: key, we include it in the body of the letter, and it will be correctly processed when received by a mail client.

We can check the work of notifications by, for example, stopping MySQL:

service mysqld stop

By default Nagios will write 3 messages to log with the status CRITICAL\SOFT every minute, and every fourth message will receive the status of CRITICAL\HARD. After that, the command notify-service-by-email will be initiated. It will send the text of the message through msmtp with keys set up above. As a result, within 4-5 minutes, a message similar to this one must be sent to mail: