Commit 9411ef33 authored by Göktuğ Kayaalp's avatar Göktuğ Kayaalp

Add msmtpqueue scripts from msmtp Debian package

parent b8497d54
#!/usr/bin/env bash
# Set secure permissions on created directories and files
umask 077
# Change to queue directory (create it if necessary)
if [ ! -d "$QUEUEDIR" ]; then
mkdir -p "$QUEUEDIR" || exit 1
cd "$QUEUEDIR" || exit 1
# Create new unique filenames of the form
# MAILFILE:[-x].mail
# MSMTPFILE:[-x].msmtp
# where x is a consecutive number only appended if you send more than one
# mail per second.
BASE="`date +%Y-%m-%d-%H.%M.%S`"
if [ -f "$BASE.mail" -o -f "$BASE.msmtp" ]; then
while [ -f "$TMP-$i.mail" -o -f "$TMP-$i.msmtp" ]; do
i=`expr $i + 1`
# Write command line to $MSMTPFILE
echo "$@" > "$MSMTPFILE" || exit 1
# Write the mail to $MAILFILE
cat > "$MAILFILE" || exit 1
# If we are online, run the queue immediately.
# Replace the test with something suitable for your site.
#ping -c 1 -w 2 SOME-IP-ADDRESS > /dev/null
#if [ $? -eq 0 ]; then
# > /dev/null &
exit 0
#!/usr/bin/env bash
for i in $QUEUEDIR/*.mail; do
egrep -s --colour -h '(^From:|^To:|^Subject:)' "$i" || echo "No mail in queue";
echo " "
#!/usr/bin/env bash
# wait for a lock that another instance has set
while [ -e "$LOCKFILE" -a "$WAIT" -lt "$MAXWAIT" ]; do
sleep 1
WAIT="`expr "$WAIT" + 1`"
if [ -e "$LOCKFILE" ]; then
echo "Cannot use $QUEUEDIR: waited $MAXWAIT seconds for"
echo "lockfile $LOCKFILE to vanish, giving up."
echo "If you are sure that no other instance of this script is"
echo "running, then delete the lock file."
exit 1
# change into $QUEUEDIR
cd "$QUEUEDIR" || exit 1
# check for empty queuedir
if [ "`echo *.mail`" = '*.mail' ]; then
echo "No mails in $QUEUEDIR"
exit 0
# lock the $QUEUEDIR
touch "$LOCKFILE" || exit 1
# process all mails
for MAILFILE in *.mail; do
MSMTPFILE="`echo $MAILFILE | sed -e 's/mail/msmtp/'`"
echo "*** Sending $MAILFILE to `sed -e 's/^.*-- \(.*$\)/\1/' $MSMTPFILE` ..."
if [ ! -f "$MSMTPFILE" ]; then
echo "No corresponding file $MSMTPFILE found"
echo "FAILURE"
if [ $? -eq 0 ]; then
echo "$MAILFILE sent successfully"
echo "FAILURE"
# remove the lock
rm -f "$LOCKFILE"
exit 0
- Use '#!/usr/bin/env bash' instead of '#!/bin/sh' because the scripts might
use features that are only available in bash and not in POSIX /bin/sh.
- Avoid the variable name SECONDS in because it is predefined
by bash.
- Fix An error made while applying the previous patch
accidently broke it. Reported by Thomas Weber. Thanks!
- Print the recipients of a mail in Patch by Konrad
Schrempf. Thanks!
- Pass options from to msmtp. Patch by Thomas Weber. Thanks!
Version 0.5:
- Added the script, contributed by Andreas Kneib.
Version 0.4:
- Frank Thieme sent the following improvements:
- now uses a lock file to prevent two instances of the
script from running simultaneously.
- now checks if you're online, and calls
immediately if this is the case.
This functionality is commented out; you have to adapt the online check to
your system before activating it.
* NOTE: Please have a look at the msmtpq scripts by Chris Gianniotis. They *
* provide a more advanced alternative to the msmtpqueue scripts. *
Scripts to queue mails and send them all at a later point with msmtp.
These scripts may be useful for dialup connections: You can "send" all your
mails offline (they will be queued by and really send them
all later when you are online (by running
Let your MUA "send" mails with this script.
It will store all mails in a queue directory for later delivery.
This script will save two files for each mail: one contains the mail, the
other one contains the command line for msmtp (including options and the
recipients). Thus you can use all msmtp options with this script.
Example (using Mutt):
In your Mutt configuration file, replace
set sendmail="/path/to/msmtp [options]"
set sendmail="/path/to/ [options]"
This script cannot detect errors in its command line or the msmtp
configuration file. You won't see error messages before
runs msmtp to send the mails. So test your msmtp configuration before using
Run this script when you are online to send all mails in the queue
It will use the saved msmtp command line for each mail.
Mails sent successfully will be deleted from the queue directory.
Mails whose delivery failed will be left untouched; you may want to edit
them, delete them by hand or simply run at a later time.
This script lists all the mails in the queue.
- If you want to change the queue directory, change the value of QUEUEDIR
in *all* scripts.
- The scripts expect exclusive access to the queue directory. Don't save other
files in it!
- Each mail will be saved in a file called[-x].mail where
cc-yy-mm is the current date, is the current time, and x is a
consecutive number only appended if you send more than one mail per second.
The msmtp command line will be saved in a file called[-x].msmtp (the same file name with ".msmtp" instead of
These scripts are simple and dumb. Change them to meet your requirements!
Please send any improvements you make to <> for inclusion in
later versions.
......@@ -4,6 +4,7 @@ export MYFS=/igk
export EMAIL=$USER@localhost
export MAILDIR=$HOME/posta
export PS1='\$ '
export PASSWORD_STORE_DIR=$HOME/fil/pass
export TROFFONTS=$HOME/.fonts
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment