Subject: bug#26359: 25.2; smtpmail.el tries useless unauthenticated connection

From: Ulrich Mueller <[email-masked]>
Date: Tue, 4 Apr 2017 12:21:22 +0200

Some mail servers implement a policy that limits the number of
concurrent or quasi-concurrent connections per host. The method how
smtpmail.el connects to a server doesn't help to avoid such limits.

In detail: smtpmail.el will always try an unauthenticated connection
first by calling smtpmail-via-smtp without the ask-for-password
argument. If the mail server allows only authenticated connections,
it will reject the connection either with status 530 "auth required"
or with status 554 "relaying denied". smtpmail-via-smtp catches these
errors and subsequently calls itself, but now with ask-for-password
set to t.

However, if the server has implemented a policy as mentioned above,
that retry may be enough to trip the limit and the second connection
will be refused by the server.

So could this be made configurable please, such that smtpmail will
immediately try with an authenticated connection? AFAICS, this should
be easily possible in either smtpmail-via-smtp or in its callers, by
conditionally setting ask-for-password depending on some configuration
variable.

Currently I am working around the problem with an advice:
(defadvice smtpmail-via-smtp
  (around always-ask-for-password
	  (recipient smtpmail-text-buffer &optional ask-for-password)
	  activate)
  (let ((ask-for-password t))
    ad-do-it))

In GNU Emacs 25.2.1 (x86_64-pc-linux-gnu, X toolkit)
 of 2017-03-28 built on juno
Windowing system distributor 'The X.Org Foundation', version 11.0.11903000
System Description:	Gentoo Base System release 2.3

Configured using:
 'configure --prefix=/usr --build=x86_64-pc-linux-gnu
 --host=x86_64-pc-linux-gnu --mandir=/usr/share/man
 --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
 --localstatedir=/var/lib --disable-dependency-tracking
 --disable-silent-rules --docdir=/usr/share/doc/emacs-25.2_rc2
 --htmldir=/usr/share/doc/emacs-25.2_rc2/html --libdir=/usr/lib64
 --program-suffix=-emacs-25 --infodir=/usr/share/info/emacs-25
 --localstatedir=/var
 --enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
 --with-gameuser=:gamestat --without-compress-install
 --with-file-notification=inotify --enable-acl --with-dbus
 --without-modules --with-gpm --without-hesiod --without-kerberos
 --without-kerberos5 --with-xml2 --without-selinux --with-gnutls
 --without-wide-int --with-zlib --with-sound=alsa --with-x
 --without-ns --without-gconf --with-gsettings
 --without-toolkit-scroll-bars --with-gif --with-jpeg --with-png
 --with-rsvg --with-tiff --with-xpm --with-imagemagick --with-xft
 --without-cairo --with-libotf --with-m17n-flt --with-x-toolkit=lucid
 --with-xaw3d GENTOO_PACKAGE=app-editors/emacs-25.2_rc2
 'CFLAGS=-march=core2 -ggdb -O2 -pipe' CPPFLAGS= 'LDFLAGS=-Wl,-O1
 -Wl,--as-needed''

Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS
NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB LUCID X11

Important settings:
  value of $LC_CTYPE: en_GB.UTF-8
  value of $LANG: POSIX
  locale-coding-system: utf-8-unix