help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't send mail with smtpmail "any more". (Gmail and other providers


From: Jean Louis
Subject: Re: Can't send mail with smtpmail "any more". (Gmail and other providers)
Date: Sun, 1 Nov 2020 16:05:01 +0300
User-agent: Mutt/+ (1036f0e) (2020-10-18)

* Saša Janiška <gour@atmarama.com> [2020-11-01 15:35]:
> On Tue, 27 Oct 2020 17:15:56 +0200
> Eli Zaretskii <eliz@gnu.org> wrote:
> 
> > smtpmail.el has a debug facility, whereby you can set a variable and
> > get a buffer with the details of the connection session.
> 
> What about adding some regular logging facility to smtpmail.el? It is
> the main reason why I'm using msmtp instead?
> 
> (This email is still sent by Claws until I decide which client to
> use: Gnus or mu4e.)

M-x rmail is quite good client for email handling in Emacs.

Then there is:

M-x mh-rmail which may have many good power users' options

For me, due to nature of my email handling and having over 50000
Maildir directories inside of ~/Maildir and that none of Emacs clients
is handling Maildirs, I am using mutt email client. That is one of
most efficient for me. And I am launching it inside of Emacs and
editing files with Emacs by using emacsclient

(defun mutt-emacs ()
  "Opens mutt in ansi-term buffer within GNU Emacs"
  (interactive)
  (let* ((default-directory (getenv "HOME")))
    (ansi-term "mutt")))

But my M-x becomes not usable when I am in ansi-term, I would like
that it is usable. 

I made this function to open up mutt in vterm and I still use it. But
that was workaround from time when ansi-term was not handling best
some terminal activities. Bugs have been polished and now ansi-term
works just fine.

(defun mutt-vterm ()
  "Opens mutt in vterm buffer within GNU Emacs"
  (interactive)
  (let* ((default-directory (getenv "HOME"))
         (buffer-exist (get-buffer "mutt"))
         (vterm-kill-buffer-on-exit t)
         (vterm-shell "mutt")
         (last-key (last-key)))
    (if buffer-exist
        (if (and (not (symbolp last-key))
                 (not (= last-key 8388717)))
            (vterm "mutt")
          (if (and (not (string-match (buffer-name (current-buffer)) "mutt"))
                   (y-or-n-p "Buffer `mutt' exists, do you wish to switch?"))
              (switch-to-buffer "mutt")))
      (vterm "mutt"))))

(global-set-key (kbd "s-m") 'mutt-you-name-it)

For fetching emails I recommend using GNU mailtools and setting up
crontab to regularly fetch emails to local computer.

For sending, I recommend using the MTA on the system if such exists on
your system, for example exim, courier MTA, OpenSMTPD, Postfix and
similar. Those are handling the queues well if you have good
connection to Internet.

msmtp is excellent tool and handles queues of email even if connection
to Internet is sporadic. MTAs need to be configured to handled mail in
queues for longer time and for that reason some emails could be lost
or returned back.

I am using those scripts for msmtp, like list queue and similar. So
the script below is at ~/bin/sendmail and my PATH is ~/bin as well so
Emacs will recognize it as sendmail and dispatch email without any
further settings to msmtp. That is very handy when using it with emacs
-Q when one needs to M-x report-emacs-bug

~/bin/sendmail follows below:

#!/usr/bin/env bash

QUEUEDIR=$HOME/.msmtpqueue

# 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="`/bin/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 stw1.rcdrun.com > /dev/null 
if [ $? -eq 0 ]; then
        msmtp-runqueue.sh > /dev/null &
fi

exit 0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]