13

I don't like waking up early but people prefer to be emailed in the morning rather than at 3AM. Therefore I often use at to send the email whilst I'm asleep.

But that comes with the complication that I need to write the email as a text file and send it with sendmail. I leave those not yet sent emails in Mutt's postponed mbox. Is there a way to use mutt to send that email?

OK, one way to send a mail later with mutt is the following:

echo 'cat /home/grochmal/body | mutt -s "mail" [email protected]' | at now + 12 hours

But I have that mail in the postponed mbox.

If I have only a single postponed mail, I can do this:

echo '/usr/sbin/sendmail -t <(cat /home/grochmal/mail/postponed | sed 1d)' | at now + 12 hours

But I often have several postponed emails in my postponed mbox, how do I select the one I want to send?

The relevant parts of my muttrc are:

set sendmail  = "/usr/sbin/sendmail -oem -oi -f $EMAIL"
set folder    = $HOME/mail
set record    = +sent
set postponed = +postponed

My /usr/sbin/sendmail is just a softlink to the postfix wrapper.

11
  • Interactively: Shift-r to open a menu. On the command line: mutt -p. Not sure what happens when you have several postponed messages and you run mutt -p, but I presume it's easy to experiment and find out. Sep 17, 2016 at 3:32
  • @SatoKatsura - Ooops, I just noticed that I have not been clear. I made a small revamp of the question. In summary, I normally use at to send emails because I'm asleep during the period I want the email to come out.
    – grochmal
    Sep 17, 2016 at 3:53
  • @SatoKatsura - Oh yeah, just tested, mutt -p simply opens the postponed mbox (and displays a list of postponed messages) when there is more than one.
    – grochmal
    Sep 17, 2016 at 3:55
  • 3
    Then you're using the wrong tool for the job. Send messages normally. Configure your MTA to defer messages by default, then flush the queue from cron between night hours. Sep 17, 2016 at 4:45
  • 2
    I'd suggest using a maildir instead of an mbox for postponed messages; then you can use a simple shell for loop to loop over all postponed mail and send it out. You can even get fancy and add a custom header to each that determines when it should be sent. May 15, 2019 at 20:53

1 Answer 1

5

I've discovered this script msmtpqueue mentioned by whereistejas on irc.freenode.net/neomutt

Change your smtp command to msmtp-enqueue.sh. Emails will be queued instead of being sent. You can send them later with msmtp-runqueue.sh. To schedule sending you can use at(1).

All emails in a queue are sent when msmtp-runqueue.sh is executed. But with a little change to msmtp-runqueue.sh you can schedule multiple bulks to be sent.

QUEUEDIR=${QUEUEDIR:-~/.msmtpqueue}

To send messages in two different bulks you can:

  1. enqueue the first bulk
  2. move the QUEUEDIR
  3. schedule msmtp-runqueue.sh with at(1) with QUEUEDIR env var pointing to the new directory location
  4. repeat steps for second bulk
2
  • Just did have the time to try it, it is pretty neat (+1). Very simple but well made piece of code, with proper locks and wait times. Can be cron-ed or at-ed. I believe it is good enough to be considered part of the mutt family of scripts.
    – grochmal
    Dec 9, 2019 at 17:01
  • Can we do something similar with postfix + smtp? Oct 6, 2021 at 3:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .