June 18, 2024

Set up msmtp to queue sent emails’ when you are offline

Last updated in September 2024

When your computer isn’t connected to the internet, you can use msmtpq to queue emails that you would like to sent once the computer is connected to internet again. As soon as your computer is connected, all you have to is run the command $ queue-msmtpq -r and all emails queued will be sent (you can also select which queued emails you’d like to send).

To set up msmtpq I followed /usr/share/doc/msmtp/examples/msmtpq/README.msmtpq and the short section on msmtpq of a blog post titled Msmtp: A simple mail transfer agent.

Below I describe the steps I took.

Get the msmtpq configuration files ready

Copy the following files:

sudo cp /usr/share/doc/msmtp/examples/msmtpq/msmtpq /usr/local/bin/
sudo cp /usr/share/doc/msmtp/examples/msmtpq/msmtp-queue /usr/local/bin/

In /usr/local/bin/msmtpq update:

Q=~/.msmtp.queue

to:

Q=~/.msmtp/mailqueue

*The caveat of this setup is that you’ll need to copy and update the file msmtp-queue if your reinstall and restore your system; assuming your backup /home. The rest below will be restored with /home.

Next, in the folder of your user i.e. ~/, do:

$ mkdir .msmtp/mailqueue/
$ touch .msmtp/mailqueue/msmtpq
$ echo > .msmtp/mailqueue/msmtpq << EOF
Q=~/.msmtp/mailqueue
LOG=~/.msmtp/log/msmtp.queue.log

The above commands (1) create a folder mailqueue, then (2) a file msmtpq, then the following command starting with echo insert the last two rows of these snippet into the file msmtpq.

Update .muttrc

Now we need to tell Mutt’s configuration file about the change.

To do so, update the following line in the file .muttrc:

set sendmail ="/usr/local/bin/msmtpq" 

And add the following line

set sendmail_wait = -1

still in in .muttrc:

Update permission

Please note: You might need to update file permissions, check Msmtp: A simple mail transfer agent.

Test that you can queue sent’ emails while offline

To test msmtpq, disconnect from the internet and send an email. Mutt should print Mail sent on the prompt, at the bottom.

To check that the email was queued, run:

$ msmtp-queue

The terminal should print something like:

  mail  num=[ 1 ]  id=[ 2024-06-13-18.11.00 ]
From: JD <j@d.com>
To: j@d.com
Subject: test msmtpq

Create an alias

Create an alias so instead of typing msmtp-queue on the command line to check the queue, you just have type queue.

In ~/.bash_aliases add:

alias queue='msmtp-queue'

You can pass the options msmtp-queue offers to the alias fine, for example to list the help menu run:

$ queue -h

personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki msmtp mutt offline

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2024 by yctct is licensed under CC BY-ND 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88