msmtpq
is a drop-in replacement formsmtp
to queue an outgoing message. It never blocks and never actually sends messages.msmtpq-flush
sends reliably queued messages.
- Send messages with
msmtpq
instead ofmsmtp
. - Install and enable the provided systemd units to automatically flush queued messages.
msmtp-queue.service
- Invokes msmtpq-flush to flush queued messages, if any.msmtp-queue.timer
- Invokes msmtp-queue.service every 10 minutes. This will allow you to send mail while offline.msmtp-queue.path
- Invokes msmtp-queue.service immediately when a message is queued. This is the fast-path for sending mail immediately you're online.
These scripts really shouldn't ever eat your mail although you may end up sending the same email twice on very rare occasions. However, if you send a message while offline, they'll only re-try once every 10 minutes.
Also note, these scripts look for/put configs/logs in non-standard directories:
- GONFIG (msmtp config):
$XDG_CONFIG_HOME/msmtp/config
. - LOG:
$XDG_LOG_HOME/msmtp.log
($XDG_LOG_HOME
defaults to~/.local/log
). - QUEUE_DIR (mail queue):
$XDG_DATA_HOME/mail.queue
.
These are defined as variables at the top of the provided scripts.
This is a highly simplified script assuming you already have the above-mentioned msmtp config file and set up XDG variables.
git clone https://github.com/Stebalien/msmtp-queue.git /tmp/msmtpq
sudo cp /tmp/msmtpq/msmtpq* /usr/local/bin
mkdir -p ~/.config/systemd/user $XDG_DATA_HOME/mail.queue
cp /tmp/msmtpq/systemd/msmtp-queue.* ~/.config/systemd/user
systemctl --user enable msmtp-queue.path msmtp-queue.timer
Afterwards, update your mutt configuration to use msmtpq instead of msmtp.
This fork maintains a MacOS/homebrew port.
WHY? Because it's pretty much-bullet proof and the default scripts were NIH.