Score:0

How to send Monit alerts with MSMTP?

it flag
Ben

I've got a Debian 11 system running as a local file server. I want to keep it as simple as possible but have some basic monitoring from Monit. I've installed and configured msmtp and msmtp-mta and I've confirmed that I can send test messages from the command line with

mail -s "test" [email protected] <<END
This is a test
END

and I've got emails coming through from unattended-upgrades.

I've seen guides where SMTP details are entered in the Monit config files, but I would prefer to only have the details stored in one place (/etc/msmtprc), so in my monit config file I've put set mailserver localhost. Monit is trying and failing to connect - in /var/log/monit.log I see:

[2023-04-25T16:43:24+0100] error    : Cannot connect to [localhost]:25 -- Connection refused
[2023-04-25T16:43:24+0100] error    : Cannot open a connection to the mailserver localhost:25 -- Operation now in progress
[2023-04-25T16:43:24+0100] error    : Mail: Delivery failed -- no mail server is available

Have I misunderstood something?

HBruijn avatar
in flag
It appears the MTA daemon component of msmtp is not running (yet). A succesful mail command is not a test to check the daemon (`mail` makes use of the `/usr/lib/sendmail` function rather than connecting to port 25) https://marlam.de/msmtp/msmtp.html#Minimal-SMTP-server-_0028msmtpd_0029
Score:0
it flag
Ben

Thanks @HBruijn, I thought it was something like that - the daemon was installed but not running.

I found a guide on how to set this up manually, but then I realised that the Debian package comes with an msmtpd.service file already (which was disabled), so I simply needed to run systemctl enable msmtpd.service and systemctl start msmtpd.service.

I then hit a permissions issue, which is described here - I ran chgrp msmtp /etc/msmtprc and chmod g+r /etc/msmtprc to allow the process to read the config file, and now it's working.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.