
msmtpq is a modification of the scripts comprising Martin Lambers'
msmtpqueue package ; it attempts be useful to msmtp by holding mail sent
by an MUA when a machine, e.g. a laptop, is not connected to the net ;
queued mails are held as files in a user defined and created queue
directory ; when the machine is connected all mail can be sent directly
out ; the msmtpq package does queue handling for msmtp according to the
way the queue is used

  msmtpq        accepts mail input from an MUA (e.g. mutt) and sends it
                directly out via msmtp if possible - or queues it if not

  msmtp-queue   is a wrapper script which simply calls msmtpq with the
                --q-mgmt argument ; it exposes routines for queue
                management and maintenance, that is, for queue display,
                queue run (flush), mail purge from the queue, etc.

msmtp-queue is interactive at the command line while msmtpq, called
directly, has no interactive user input whatever - it simply takes its
input from the MUA and outputs directly to msmtp (or to the queue)

credit goes to Martin Lambers for the idea of the queue ; any bugs,
design errors, oversights, suggestions for improvement, etc. belong to
me ; all feedback is welcome ; I can be reached via the msmtp mailing
list


Installation :
------------

copy msmtpq and msmtp-queue to whatever location is best for you
(I use /usr/local/bin) ; the directory chosen should be on the path

replace the msmtp invocation in your mail client with msmtpq ; e.g. for
mutt : 'set sendmail = /path/to/msmtpq'

msmtpq will then take care of the management and routing of outgoing
mail ; normally sending a mail is nearly instantaneous, but a very long
mail (e.g. one with large attachments) can take some time to make its way
through ; therefore it's wise to have the MUA background the process if
possible

In the case of mutt, in addition to the above setting,

'set sendmail = /path/to/msmtpq'

set, also

'set sendmail_wait = -1'

mutt then backgrounds the send and watches for a return code & message
from msmtpq


Configuration :
-------------

all config is done within the msmtpq script

  set the MSMTP var to point to the location of the msmtp executable
    (only if necessary ; if it's not on the path)
  set the Q var to point to the location of the queue directory
  set the LOG var to point to the location of the queue log

the MSMTP variable can have the location of the msmtp executable entered
into it if it is not on the path ; this might be useful in unusual
circumstances, such as embedded systems, etc. ; otherwise, if you are
running a normal Linux distribution you can leave it as is ; msmtp will
by default be on the execution path

the Q variable should have the location of the queue directory

the LOG variable should have the desired name & location of the queue log

the locations are clearly marked near the beginnings of the script ;
modify all to the locations you prefer (the defaults work for me ; you
may or may not be happy with them) ... please note that it's preferable
to create the queue directory (with 0700 permissions) before using these
routines

note that the default msmtpq set up creates a separate log for queue
operations ; all operations which modify the queue in any way are logged
to the queue log ; this is distinct from the msmtp log set by the
'logfile' setting in .msmtprc ; I've been persuaded that it's better to
have separate logs (for the distinct functions) ; if this doesn't sit
well with you it's possible to define the queue log to be the same log
file as the one defined in .msmtprc ; it's also possible to turn off
queue logging entirely (by commenting out the 'LOG=' var - to be
'#LOG=') but this seems hardly advisable, particularly before you are
confident that all is working

mutt users please take note of the additional setup instructions in the
msmtp docs & man page.


to use msmtpq with additional options :

set sendmail = "/path/to/msmtpq"
                 # normal config for mutt to use the queue
                 # (by default the ping connection test is enabled)
set sendmail = "EMAIL_CONN_NOTEST=t /path/to/msmtpq"
                 # use queue without a net connection test

set sendmail = "EMAIL_CONN_TEST=p /path/to/msmtpq"
                 # use queue with ping connection test (the default)
set sendmail = "EMAIL_CONN_TEST=P /path/to/msmtpq"
                 # use queue with faster ping connection test
                 # (to an IP address, without a DNS lookup)
set sendmail = "EMAIL_CONN_TEST=n /path/to/msmtpq"
                 # use queue with netcat connection test
                 # (netcat must be installed on user's system)
set sendmail = "EMAIL_CONN_TEST=s /path/to/msmtpq"
                 # use queue with sh sockets connection test
                 # (this does *not* work on Debian systems
                 #  socket use is not compiled into bash for
                 #  security on multiuser systems - it may not be
                 #  a serious consideration, however, on
                 #  single user workstations - e.g. on laptops -
                 #  or in embedded systems)

set sendmail = "EMAIL_QUEUE_QUIET=t /path/to/msmtpq"
                 # use queue ; suppress messages and 'chatter'
                 # good, apparently, for use w/emacs

multiple environmental vars may be used on the command line,
space separated, before the msmtpq invocation


in summary :
  copy the msmtpq and msmtp-queue scripts to the directory where they will live
    be certain that they are executable
      ( chmod +x msmtpq msmtp-queue )
  create the queue dir (0700) if necessary
    ( mkdir -p /path/to/queue/dir )
    ( chmod 0700 /path/to/queue/dir )
  enter or confirm the values of the three config vars in msmtpq
  for mutt users -
    set sendmail="/path/to/msmtpq"   ("ANY_ENV_VARS_HERE /path/to/msmtpq")
    set sendmail_wait = -1
    set use_from=yes
    set realname="Your Name"
    set from=you@example.com
    set envelope_from=yes
    (and perhaps more on the msmtp man page & docs ...)
  for other MUAs -
    set the mta to '/path/to/msmtpq', as above
    background its execution, if possible


log(s) rotation :

On a Debian or Debian-based system (e.g. Ubuntu or Mint) a file can be
created in /etc/logrotate.d (named, e.g. 'msmtp') that configures
logrotate to compress and rotate both the msmtp logs and msmtpq queue
logs.

Suggested contents :
#--------------------------------------------------
/home/xyz/log/msmtp.log /home/xyz/log/msmtp.queue.log {
  rotate 9999
  weekly
  compress
  notifempty
  missingok
}
#--------------------------------------------------

adjust it to your queue and log location(s) and name(s) and
see the logrotate man page for further config information ;
it should be trivial to adapt to other systems

That's it.


Usage :
-----

msmtpq is entirely self contained ; beyond keeping an eye on the queue
and queue logs it should require no admin or user attention once set up


msmtp-queue offers the following options :

  msmtp-queue -r -- runs (flushes) all the contents of the queue

  msmtp-queue -R -- sends selected individual mail(s) in the queue

  msmtp-queue
  msmtp-queue -d -- displays the contents of the queue   (<-- default)

  msmtp-queue -p -- allows the specific purging of one or more mails

  msmtp-queue -a -- purges all mail in the queue

  msmtp-queue -h -- offers a helpful blurt

( msmtp-queue does not log the 'chatter' of user interaction but logs,
  to the queue log, any event that changes the queue in any way )


I find it useful to have a display of the number of mails currently
in the queue in conky ; it uses one shell line (in the .conkyrc script) :

mail queue : ${exec /bin/ls -1 ${HOME}/.msmtp.queue/*.mail 2>/dev/null | /usr/bin/wc -l}


With hopes that it's useful,

Chris Gianniotis
