[patch] Added support for local /usr/sbin/sendmail to send email alerts

Issue #134 closed
Lonnie Abelbeck created an issue

Hi,

I'm a developer for the AstLinux open source project, a Linux based appliance providing SIP, XMPP and other services. http://www.astlinux.org

One of our developers discovered your excellent Monit project, which appears to be a great match for our project, but there is a problem with sending email alerts... let me explain and provide a possible solution.

We have built an outgoing email queue via /usr/sbin/sendmail which then delivers via msmtp as the SMTP client. Robust outgoing email is critical for us since they are commonly voicemail attachments from Asterisk (SIP PBX). Email alerts from Monit are no less important. Additionally the msmtp outbound SMTP network settings are already defined for other application's use.

As such we have created a patch against Monit 5.10 which allows "set mailserver localhost" to use /usr/sbin/sendmail instead of a local SMTP server.

Attached is "monit-0100-localhost-sendmail.patch" or can be found here: http://svn.code.sf.net/p/astlinux/code/branches/1.0/package/monit/monit-0100-localhost-sendmail.patch

Developer Summary:

1) The new sendmail_local() taps early into the sendmail() function when the mailserver is "localhost". If this patch is (hopefully) accepted there would be an additional option test to treat localhost in this manner.

2) sendmail_local() is quite simple, create a temporary file (0600 permissions) containing the email specifics and pass that to "/usr/sbin/sendmail -t" via a system command.

The system command is modeled how Asterisk voicemails are sent to sendmail:

( /usr/sbin/sendmail -t < /tmp/monitmail-123456 ; rm -f /tmp/monitmail-123456 ) &

3) Finally, the above system command is issued via a new function spawn_system_cmd() based on your existing spawn() function.

If this patch is accepted, the mailcmd string "/usr/sbin/sendmail -t" should be user definable and when defined sendmail_local() is called for "localhost". I have kept things simple at this point in the unfortunate chance we will be manually maintaining this patch ourselves. :-)

Please give this patch consideration. Thanks.

Lonnie

Comments (11)

  1. Lonnie Abelbeck reporter

    While I see the added feature of the pull request you mentioned is very useful, it adds complexity for the simple task of calling sendmail instead if a localhost SMTP server.

    If I understand it correctly, for every set of From:/To: emails an alertcommand would have to be created along with a shell script wrapper to bundle things together to call sendmail ? While my patch only apples to email (not uncommon :-) ) it provides a very simple solution to the user, just define "/usr/sbin/sendmail -t" somewhere in the config.

  2. Tildeslash repo owner

    The solution which we described in the pull request response is similar to what you want ... the user will only define the shell command once (globally), such as:

    set alert:sendmail as "/usr/sbin/sendmail -t"
    

    this will allow to select the "sendmail" as an alert channel to be used - it's not necessary to repeat the command.

    The patch you propose will address only one very specific use case and will switch the whole alerting to sendmail CLI ... it won't allow to add for example script for SMS notification, etc.

    Note that Monit also has event queue support - when you need to push email to local mailserver, you can let sendmail listen on loopback and use 127.0.0.1:25 ... if sendmail won't be accessible, monit will put the event to the queue and retry next cycle. I think that provides solid alert delivery already (no need to pass the alert via CLI utility).

  3. Lonnie Abelbeck reporter

    Hi,

    Monit not supporting /usr/sbin/sendmail is still a big problem for us. It seems almost every new release version of Monit requires us to recreate our patches, and now with the recent 5bda57c commit we will have to start over yet again.

    BTW, our sendmail patch for Monit 5.17.1 is here: http://svn.code.sf.net/p/astlinux/code/branches/1.0/package/monit/monit-0100-localhost-sendmail.patch

    Please reconsider adding support for a local MTA such as /usr/sbin/sendmail.

    Thanks,

    Lonnie

  4. Tildeslash repo owner

    Hi Lonnie,

    we prefer the generic solution described in the previous message: generic method to set any number of custom alert channels (can be used to send SNMP trap, pipe to /usr/bin/sendmail, etc.). We're sorry we're currently with other tasks, this feature is on our roadmap.

    Best regards, Monit team

  5. Former user Account Deleted

    The solution which we described in the pull request response is similar to what you want ... the user will only define the shell command once (globally), such as: set alert:sendmail as "/usr/sbin/sendmail -t"

    It's sad to see this old issue still open. I would love to see a solution for this. Sadly the PR #19 was closed.

    Tildeslash repo owner Thank you. We are just about to start refactoring/rewriting Monit so the code will be completely different. Maybe best to wait until we have the basics in place. 2014-09-12 Has something happened here on the base so anyone from the community could catch up from this point?

    My solution so far is to spawn a small fake STMP server which can then execute custom cli commands.

  6. Lonnie Abelbeck reporter

    2020 Followup:

    The msmtp project by “Martin Lambers” now includes a msmtpd daemon that can listen on 127.0.0.1 and send SMTP requests by monit using:

    set mailserver 127.0.0.1 port 25

    Works perfectly.

  7. Danny Weldon

    Most Linux distros provide a local SMTP server such as postfix, so you should be able to just set the mailserver to localhost as per Lonnie’s suggestion. Note that postfix provides a sendmail wrapper binary for compatibility.

  8. Log in to comment