2

Removing mutt's send delay

I originally used mutt's built-in SMTP MTA. However, there is a considerable pause after hitting send. This can be disabled by using an external MTA with set sendmail_wait=-1 in muttrc.

However, if I use msmtp as the MTA, then there is no notification of errors (although msmtp does write to logfile as specified in ~/.msmtprc).

Attempt to get notifications

From the command line, I can trigger a command when msmtp fails.

</tmp/tosend msmtp -a default foo@bar.com --read-envelope-from || echo failed

Conceivably, I could mail a failure notification to my local *nix mail. However, this doesn't seem to work in mutt, if I set the following in muttrc.

set sendmail = "/usr/bin/msmtp || date >> /tmp/msmtp.fail"

This causes all email to fail to send silently, with the following error in msmtp's logfile.

Nov 05 10:53:09 host=mail.bar.com tls=on auth=on user=foo@bar.com from=foo@bar.com recipients=||,date,>>,/tmp/msmtp.fail,foo@bar.com smtpstatus=501 smtpmsg='501 #5.1.1 bad address ' errormsg='recipient address >> not accepted by the server' exitcode=EX_DATAERR

Obviously, mutt is parsing the extra parts of the command as recipients.

Question

Is there a way to get notifications of sent emails that fail, while sending in the background? I'm not tied to msmtp necessarily.

Sparhawk
  • 19,941

3 Answers3

4

Write yourself a tiny shell script to use as a "sendmail" value. Eg configure ~/.muttrc with

set sendmail = /home/yourid/bin/mymuttsendmail

and in mymuttsendmail put something like

#!/bin/bash
tmp=$(mktemp /tmp/mymutt.XXXXXX)
cat >$tmp
( if ! msg=$(msmtp "$@" <$tmp 2>&1)
  then zenity --error --text "$msg"
  fi 
  rm $tmp
) &
exit 0

and chmod +x this file. Remember this script will be called with the recipients as extra args, which we pass to msmtp with "$@", and the mail will be on stdin, which we copy immediately into a temporary file to then give to msmtp. Any error messages are captured in variable msg and if the return code is a failure you can run a popup dialog like zenity, for example.

meuh
  • 51,383
  • Interesting solution! (+1) However, I feel like exim may be more robust, so I'll persist with working that out. I'll revisit your answer if I give up with exim. – Sparhawk Nov 08 '15 at 22:46
  • Hmm, this doesn't seem to work. The sent mail is severely garbled. It seems to strip off most headers, and the body is absent. I retried with vanilla msmtp as $sendmail, and that worked fine. – Sparhawk Nov 11 '15 at 06:04
  • I think I know what might be happening. I've edited the script to capture the mail first into a temporary file, then run msmtp in the background. – meuh Nov 11 '15 at 07:24
  • Thanks, this works perfectly now. (I suppose that was related to the "open attachment in external program" issue, where the file was deleted/truncated before fully opening?) – Sparhawk Nov 12 '15 at 09:57
  • 1
    Yes, I was being a bit naive in assuming the file behind stdin would be left intact by mutt when, as it sees it, the sending process has ended. – meuh Nov 12 '15 at 10:03
1

Have you considered using a better nullmailer, msmtp is about as minimalist as it gets? or even a full MTA like exim or postfix (they're not very difficult to configure)?

There's a list of other nullmailer options at http://linuxmafia.com/faq/Mail/nullmailers.html

cas
  • 78,579
  • Thanks for the link. I'm more than happy to use a different MTA (as per the question), and I've got exim installed anyway. However, do you know which (if any) would provide some kind of feedback or trigger a script on errors? – Sparhawk Nov 05 '15 at 02:52
  • a real MTA will bounce the message back to the sender if there was any error. btw, why even bother with msmtp if you have exim installed? – cas Nov 05 '15 at 03:20
  • Thanks. I'm testing eximnow… which is ridiculously confusing to set up (at least in Arch). I used msmtp because I followed the first few suggestions that I found for mutt. Also, after more investigation, exim requires the password stored in plaintext, and must be configured system-wide, instead of msmtp's user-level configuration. – Sparhawk Nov 05 '15 at 05:10
  • And I just can't work exim out… New question asked here. – Sparhawk Nov 07 '15 at 12:10
1

meuh's answer was very helpful. Here's a simpler version of mymuttsendmail. Replace username with your username in the following code so it can email you locally in case there's an error. The variable $? stores the exit code of msmtp, and uses local mail to email you if there's an error sending your email. Just remember to set sendmail_wait=-1.

#!/bin/bash
/usr/bin/msmtp "$@" 2>&1
VAL=$?
if (($VAL))
then 
    # message not sent
    echo "Error sending mail to $@, exit code $VAL" | mail -s 'ERROR' username
fi 
guest
  • 11