From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: How I am handling msmtp queues Date: Thu, 10 Mar 2022 09:23:45 +0300 Message-ID: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10211"; mail-complaints-to="usenet@ciao.gmane.io" To: Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 10 07:26:42 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSCG1-0002S7-IJ for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Mar 2022 07:26:41 +0100 Original-Received: from localhost ([::1]:37746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSCG0-0003SJ-KQ for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Mar 2022 01:26:40 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSCEE-0003KM-3H for help-gnu-emacs@gnu.org; Thu, 10 Mar 2022 01:24:52 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:47179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSCEC-0001Gl-9B for help-gnu-emacs@gnu.org; Thu, 10 Mar 2022 01:24:49 -0500 Original-Received: from localhost ([::ffff:154.231.200.225]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000003DE2D.000000006229998E.000012AB; Wed, 09 Mar 2022 23:24:14 -0700 Received-SPF: pass client-ip=217.170.207.13; envelope-from=support1@rcdrun.com; helo=stw1.rcdrun.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 10 Mar 2022 01:25:24 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:136426 Archived-At: I wish to describe how I use Emacs Lisp to send emails. msmtp is about sending emails from computer: Description : A mini smtp client URL : https://marlam.de/msmtp/ For longer time I have used msmtp by cron job. However, that somehow blocked itself, some colliding msmtp processes were in memory and I had to kill them all before running msmtp-runqueue.sh script Often I have thousands of emails in the queue, and sending them reliably is important. Cron job for some unknown reasons did not do well. Then I have made this Emacs Lisp function. ;;;; MSMTP (defun msmtp-count-remaining () "Count and send remaining MSMTP messages in the queue" (interactive) (let ((count (length (directory-files "~/.msmtpqueue" nil "\\.mail")))) (if (> count 0) (progn (async-shell-command "msmtp-runqueue.sh" "*msmtp*") (message "There is %s e-mails in queue." count)) (message "No emails.")))) And I run the function with timer so that it is repeated every minute. If there are some emails in the queue, the function will dispatch them. ;; (run-with-timer 0 60 'msmtp-count-remaining) Additionally I have adjusted the variable `display-buffer-alist' so that buffers matching "msmtp" have function `display-buffer-no-window' so that the buffer does not appear on screen when running the queue. I can run the above Lisp with M-x msmtp-count-remaining or the timer will run the script and send any messages in the queue. And original msmtp script is here: msmtp-runqueue.sh ================= #!/usr/bin/env bash QUEUEDIR="$HOME/.msmtpqueue" 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 Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/