smailq

Smailq is a mail queue for lightweight SMTP clients (MSAs) like msmtp that do not feature a queue. Smailq basically provides the functionality of sendmail and mailq.

Use case. A typical use case is the following: You have a notebook or a workstation without a full-fledged MTA (e.g., postfix) installed, but something like msmtp, esmtp, or ssmtp, which only forward the mail to an SMTP server. Such lightweight SMTP clients typically do not feature a mail queue.1 In case that your SMTP client cannot connect to the SMTP server, the mail is lost2.

Smailq implements a mail queue and uses MSAs like msmtp to actually deliver mails. It also comes with shell scripts sendmail and mailq that wrap around smailq. Note that typical Unix-type software (e.g., cron, caff, etc.) uses /usr/sbin/sendmail to send mails. Hence, if cron informs the administrator of an error while the notebook is offline, the mail is inserted into the queue instead of being dropped.

Usage

$ smailq -h

smailq is a mail queue for lightweight SMTP clients (MSAs) like msmtp that do
not provide a queue. It basically provides the functionality of sendmail and
mailq.

USAGE:

  /usr/bin/smailq --send [recipient ...] -- [MSA options ...]
  /usr/bin/smailq --list
  /usr/bin/smailq --deliver-all
  /usr/bin/smailq --deliver [ID ...]
  /usr/bin/smailq --delete [ID ...]
  /usr/bin/smailq --help
  /usr/bin/smailq --version

COMMANDS:

      --delete
          Remove the mails with given IDs from the queue.

      --deliver
          Attempt to deliver the mails with given IDs only.

      --deliver-all
          Attempt to deliver all mails in the queue.

  -h, --help
          Print this usage text.

      --list
          List all mails in the queue. This is the default

      --send
          Read a mail from stdin, insert it into the queue, and attempt to
          deliver all mails in the queue. Options after "--" are passed forward
          to the MSA for this particular mail.

  -V, --version
          Show version info.

OPTIONS:

  -C, --config=FILE
          Use the given configuration file instead of "$HOME/.smailq.conf".

  -q, --quiet
          Do not print info messages.

  -v, --verbose
          Increase output verbosity.

Configuration file

By default, smailq looks at $HOME/.smailq.conf and /etc/smailq.conf (in that order) for a configuration file, unless the configuration file is explicitly specified by an option. A configuration file with its default values would look like this:

[general]
# Optional: The directory where the log file is written to. The special
# value 'syslog' causes smailq to log to syslog.
logdir = ~/.smailq/log/
# Optional: The directory where smailq saves the mail queue data
datadir = ~/.smailq/data/

# Settings for the network (TCP) connectivity test
[nwtest]
# Optional: The host to connect to
host = www.google.com
# Optional: The port to connect to
port = 80
# Optional: The timeout
timeout = 8

# Settings concerning the mail submission agent
[msa]
# This command is called when smailq attempts to deliver a mail. The
# MSA-options passed to smailq are appended to this line.
cmd = /usr/bin/msmtp

Download

You may obtain a copy of the git repository of smailq by

$ git clone https://git.sthu.org/repos/smailq.git

or you can simply download the latest tarball.

Installation

Installation is done by simply calling make install in the source directory as a privileged user.

If you use Gentoo Linux, then you may get a copy of my Gentoo overlay. Besides mail-mta/smail, the overlay also contains a virtual/mta ebuild that takes smailq into account. If some package is depending on an mta, Gentoo portage will enforce that virtual/mta is installed, which will again pull-in a concrete package that provides /usr/sbin/sendmail. This would lead to a conflict when installing smailq by hand. Hence, it is recommended to use the respective ebuilds.

  1. msmtp for instance ships shell scripts that implement a simple queuing mechanism around msmtp. However, /usr/sbin/sendmail is still a symlink to /usr/bin/msmtp and, thereby, Unix-type software like cron would trust that msmtp queues mails that cannot be delivered right now. 

  2. It would be the responsibility of the caller of the SMTP client to queue mails, which is typically not the case.