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
QUEUEDIR=$MAILQUEUE
# 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
fi
cd "$QUEUEDIR" || exit 1
# Create new unique filenames of the form
# MAILFILE: ccyy-mm-dd-hh.mm.ss[-x].mail
# MSMTPFILE: ccyy-mm-dd-hh.mm.ss[-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
TMP="$BASE"
i=1
while [ -f "$TMP-$i.mail" -o -f "$TMP-$i.msmtp" ]; do
i=`expr $i + 1`
done
BASE="$BASE-$i"
fi
MAILFILE="$BASE.mail"
MSMTPFILE="$BASE.msmtp"
# 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
# msmtp-runqueue.sh > /dev/null &
#fi
exit 0
#!/usr/bin/env bash
QUEUEDIR=$MAILQUEUE
for i in $QUEUEDIR/*.mail; do
egrep -s --colour -h '(^From:|^To:|^Subject:)' "$i" || echo "No mail in queue";
echo " "
done
#!/usr/bin/env bash
QUEUEDIR=$MAILQUEUE
LOCKFILE="$QUEUEDIR/.lock"
MAXWAIT=120
OPTIONS=$@
# wait for a lock that another instance has set
WAIT=0
while [ -e "$LOCKFILE" -a "$WAIT" -lt "$MAXWAIT" ]; do
sleep 1
WAIT="`expr "$WAIT" + 1`"
done
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
fi
# change into $QUEUEDIR
cd "$QUEUEDIR" || exit 1
# check for empty queuedir
if [ "`echo *.mail`" = '*.mail' ]; then
echo "No mails in $QUEUEDIR"
exit 0
fi
# 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"
continue
fi
msmtp $OPTIONS `cat "$MSMTPFILE"` < "$MAILFILE"
if [ $? -eq 0 ]; then
rm "$MAILFILE" "$MSMTPFILE"
echo "$MAILFILE sent successfully"
else
echo "FAILURE"
fi
done
# remove the lock
rm -f "$LOCKFILE"
exit 0
2008-07-28:
- 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 msmtp-runqueue.sh because it is predefined
by bash.
2008-06-12:
- Fix msmtp-runqueue.sh. An error made while applying the previous patch
accidently broke it. Reported by Thomas Weber. Thanks!
2008-01-27:
- Print the recipients of a mail in msmtp-runqueue.sh. Patch by Konrad
Schrempf. Thanks!
2008-01-25:
- Pass options from msmtp-runqueue.sh to msmtp. Patch by Thomas Weber. Thanks!
Version 0.5:
- Added the msmtp-listqueue.sh script, contributed by Andreas Kneib.
Version 0.4:
- Frank Thieme sent the following improvements:
- msmtp-runqueue.sh now uses a lock file to prevent two instances of the
script from running simultaneously.
- msmtp-enqueue.sh now checks if you're online, and calls msmtp-runqueue.sh
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 msmtp-enqueue.sh) and really send them
all later when you are online (by running msmtp-runqueue.sh).
1. msmtp-enqueue.sh
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]"
with
set sendmail="/path/to/msmtp-enqueue.sh [options]"
This script cannot detect errors in its command line or the msmtp
configuration file. You won't see error messages before msmtp-runqueue.sh
runs msmtp to send the mails. So test your msmtp configuration before using
msmtp-enqueue.sh.
2. msmtp-runqueue.sh
Run this script when you are online to send all mails in the queue
directory.
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 msmtp-runqueue.sh at a later time.
3. msmtp-listqueue.sh
This script lists all the mails in the queue.
Notes:
- 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 cc-yy-mm-hh.mm.ss[-x].mail where
cc-yy-mm is the current date, hh.mm.ss 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
cc-yy-mm-hh.mm.ss[-x].msmtp (the same file name with ".msmtp" instead of
".mail").
These scripts are simple and dumb. Change them to meet your requirements!
Please send any improvements you make to <marlam@marlam.de> for inclusion in
later versions.
......@@ -4,6 +4,7 @@ export MYFS=/igk
export EMAIL=$USER@localhost
export MAILDIR=$HOME/posta
export MAILQUEUE=$MAILDIR/queue
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