diff options
| author | Lars Ingebrigtsen | 2019-07-26 12:16:49 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-26 12:16:49 +0200 |
| commit | 6216c7abd4cefd6245d29272d899490045cfdeff (patch) | |
| tree | caacf5b5373ef0739c79aa0690d7b5fd20d9e69b | |
| parent | 1573cf98ebcc3dfa2c355b9f59a6a95c681da970 (diff) | |
| download | emacs-6216c7abd4cefd6245d29272d899490045cfdeff.tar.gz emacs-6216c7abd4cefd6245d29272d899490045cfdeff.zip | |
Allow specifying that SMTP auth should always be used
* doc/misc/smtpmail.texi (Authentication): Document it.
* lisp/mail/smtpmail.el
(smtpmail-servers-requiring-authorization): New variable (bug#26359).
(smtpmail-via-smtp): Use it.
| -rw-r--r-- | doc/misc/smtpmail.texi | 14 | ||||
| -rw-r--r-- | lisp/mail/smtpmail.el | 55 |
2 files changed, 39 insertions, 30 deletions
diff --git a/doc/misc/smtpmail.texi b/doc/misc/smtpmail.texi index 365f55718e7..b2fc90a337a 100644 --- a/doc/misc/smtpmail.texi +++ b/doc/misc/smtpmail.texi | |||
| @@ -221,10 +221,18 @@ they are allowed to send mail. Authentication usually involves | |||
| 221 | supplying a user name and password. | 221 | supplying a user name and password. |
| 222 | 222 | ||
| 223 | If you have not configured anything, then the first time you try to | 223 | If you have not configured anything, then the first time you try to |
| 224 | send mail via a server, Emacs (version 24.1 and later) prompts you | 224 | send mail via a server and the SMTP server reports back that it |
| 225 | requires authentication, Emacs (version 24.1 and later) prompts you | ||
| 225 | for the user name and password to use, and then offers to save the | 226 | for the user name and password to use, and then offers to save the |
| 226 | information. By default, Emacs stores authentication information in | 227 | information. By default, Emacs stores authentication information in a |
| 227 | a file @file{~/.authinfo}. | 228 | file @file{~/.authinfo}. |
| 229 | |||
| 230 | @vindex smtpmail-servers-requiring-authorization | ||
| 231 | Some SMTP servers may bandwidth-limit (or deny) requests from clients | ||
| 232 | that try to post without authorization---even if they later do supply | ||
| 233 | that information. To make this library supply that information on | ||
| 234 | first attempt, set @code{smtpmail-servers-requiring-authorization} to | ||
| 235 | a regexp that match the server name. | ||
| 228 | 236 | ||
| 229 | @cindex authinfo | 237 | @cindex authinfo |
| 230 | The basic format of the @file{~/.authinfo} file is one line for each | 238 | The basic format of the @file{~/.authinfo} file is one line for each |
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el index 741c4393e65..acd6f145e71 100644 --- a/lisp/mail/smtpmail.el +++ b/lisp/mail/smtpmail.el | |||
| @@ -70,34 +70,29 @@ | |||
| 70 | (defcustom smtpmail-default-smtp-server nil | 70 | (defcustom smtpmail-default-smtp-server nil |
| 71 | "Specify default SMTP server. | 71 | "Specify default SMTP server. |
| 72 | This only has effect if you specify it before loading the smtpmail library." | 72 | This only has effect if you specify it before loading the smtpmail library." |
| 73 | :type '(choice (const nil) string) | 73 | :type '(choice (const nil) string)) |
| 74 | :group 'smtpmail) | ||
| 75 | 74 | ||
| 76 | (defcustom smtpmail-smtp-server | 75 | (defcustom smtpmail-smtp-server |
| 77 | (or (getenv "SMTPSERVER") smtpmail-default-smtp-server) | 76 | (or (getenv "SMTPSERVER") smtpmail-default-smtp-server) |
| 78 | "The name of the host running SMTP server." | 77 | "The name of the host running SMTP server." |
| 79 | :type '(choice (const nil) string) | 78 | :type '(choice (const nil) string)) |
| 80 | :group 'smtpmail) | ||
| 81 | 79 | ||
| 82 | (defcustom smtpmail-smtp-service 25 | 80 | (defcustom smtpmail-smtp-service 25 |
| 83 | "SMTP service port number. | 81 | "SMTP service port number. |
| 84 | The default value would be \"smtp\" or 25." | 82 | The default value would be \"smtp\" or 25." |
| 85 | :type '(choice (integer :tag "Port") (string :tag "Service")) | 83 | :type '(choice (integer :tag "Port") (string :tag "Service"))) |
| 86 | :group 'smtpmail) | ||
| 87 | 84 | ||
| 88 | (defcustom smtpmail-smtp-user nil | 85 | (defcustom smtpmail-smtp-user nil |
| 89 | "User name to use when looking up credentials in the authinfo file. | 86 | "User name to use when looking up credentials in the authinfo file. |
| 90 | If non-nil, only consider credentials for the specified user." | 87 | If non-nil, only consider credentials for the specified user." |
| 91 | :version "24.1" | 88 | :version "24.1" |
| 92 | :type '(choice (const nil) string) | 89 | :type '(choice (const nil) string)) |
| 93 | :group 'smtpmail) | ||
| 94 | 90 | ||
| 95 | (defcustom smtpmail-local-domain nil | 91 | (defcustom smtpmail-local-domain nil |
| 96 | "Local domain name without a host name. | 92 | "Local domain name without a host name. |
| 97 | If the function `system-name' returns the full internet address, | 93 | If the function `system-name' returns the full internet address, |
| 98 | don't define this value." | 94 | don't define this value." |
| 99 | :type '(choice (const nil) string) | 95 | :type '(choice (const nil) string)) |
| 100 | :group 'smtpmail) | ||
| 101 | 96 | ||
| 102 | (defcustom smtpmail-stream-type nil | 97 | (defcustom smtpmail-stream-type nil |
| 103 | "Type of SMTP connections to use. | 98 | "Type of SMTP connections to use. |
| @@ -105,7 +100,6 @@ This may be either nil (upgrade with STARTTLS if possible), | |||
| 105 | `starttls' (refuse to send if STARTTLS isn't available), | 100 | `starttls' (refuse to send if STARTTLS isn't available), |
| 106 | `plain' (never use STARTTLS), or `ssl' (to use TLS/SSL)." | 101 | `plain' (never use STARTTLS), or `ssl' (to use TLS/SSL)." |
| 107 | :version "24.1" | 102 | :version "24.1" |
| 108 | :group 'smtpmail | ||
| 109 | :type '(choice (const :tag "Possibly upgrade to STARTTLS" nil) | 103 | :type '(choice (const :tag "Possibly upgrade to STARTTLS" nil) |
| 110 | (const :tag "Always use STARTTLS" starttls) | 104 | (const :tag "Always use STARTTLS" starttls) |
| 111 | (const :tag "Never use STARTTLS" plain) | 105 | (const :tag "Never use STARTTLS" plain) |
| @@ -119,55 +113,56 @@ not include an @-sign, so that each RCPT TO address is fully qualified. | |||
| 119 | 113 | ||
| 120 | Don't bother to set this unless you have get an error like: | 114 | Don't bother to set this unless you have get an error like: |
| 121 | Sending failed; 501 <someone>: recipient address must contain a domain." | 115 | Sending failed; 501 <someone>: recipient address must contain a domain." |
| 122 | :type '(choice (const nil) string) | 116 | :type '(choice (const nil) string)) |
| 123 | :group 'smtpmail) | ||
| 124 | 117 | ||
| 125 | (defcustom smtpmail-debug-info nil | 118 | (defcustom smtpmail-debug-info nil |
| 126 | "Whether to print info in buffer *trace of SMTP session to <somewhere>*. | 119 | "Whether to print info in buffer *trace of SMTP session to <somewhere>*. |
| 127 | See also `smtpmail-debug-verb' which determines if the SMTP protocol should | 120 | See also `smtpmail-debug-verb' which determines if the SMTP protocol should |
| 128 | be verbose as well." | 121 | be verbose as well." |
| 129 | :type 'boolean | 122 | :type 'boolean) |
| 130 | :group 'smtpmail) | ||
| 131 | 123 | ||
| 132 | (defcustom smtpmail-debug-verb nil | 124 | (defcustom smtpmail-debug-verb nil |
| 133 | "Whether this library sends the SMTP VERB command or not. | 125 | "Whether this library sends the SMTP VERB command or not. |
| 134 | The commands enables verbose information from the SMTP server." | 126 | The commands enables verbose information from the SMTP server." |
| 135 | :type 'boolean | 127 | :type 'boolean) |
| 136 | :group 'smtpmail) | ||
| 137 | 128 | ||
| 138 | (defcustom smtpmail-code-conv-from nil | 129 | (defcustom smtpmail-code-conv-from nil |
| 139 | "Coding system for encoding outgoing mail. | 130 | "Coding system for encoding outgoing mail. |
| 140 | Used for the value of `sendmail-coding-system' when | 131 | Used for the value of `sendmail-coding-system' when |
| 141 | `select-message-coding-system' is called." | 132 | `select-message-coding-system' is called." |
| 142 | :type 'coding-system | 133 | :type 'coding-system) |
| 143 | :group 'smtpmail) | ||
| 144 | 134 | ||
| 145 | (defcustom smtpmail-queue-mail nil | 135 | (defcustom smtpmail-queue-mail nil |
| 146 | "Non-nil means mail is queued; otherwise it is sent immediately. | 136 | "Non-nil means mail is queued; otherwise it is sent immediately. |
| 147 | If queued, it is stored in the directory `smtpmail-queue-dir' | 137 | If queued, it is stored in the directory `smtpmail-queue-dir' |
| 148 | and sent with `smtpmail-send-queued-mail'." | 138 | and sent with `smtpmail-send-queued-mail'." |
| 149 | :type 'boolean | 139 | :type 'boolean) |
| 150 | :group 'smtpmail) | ||
| 151 | 140 | ||
| 152 | (defcustom smtpmail-queue-dir "~/Mail/queued-mail/" | 141 | (defcustom smtpmail-queue-dir "~/Mail/queued-mail/" |
| 153 | "Directory where `smtpmail.el' stores queued mail. | 142 | "Directory where `smtpmail.el' stores queued mail. |
| 154 | This directory should not be writable by other users." | 143 | This directory should not be writable by other users." |
| 155 | :type 'directory | 144 | :type 'directory) |
| 156 | :group 'smtpmail) | ||
| 157 | 145 | ||
| 158 | (defcustom smtpmail-warn-about-unknown-extensions nil | 146 | (defcustom smtpmail-warn-about-unknown-extensions nil |
| 159 | "If set, print warnings about unknown SMTP extensions. | 147 | "If set, print warnings about unknown SMTP extensions. |
| 160 | This is mainly useful for development purposes, to learn about | 148 | This is mainly useful for development purposes, to learn about |
| 161 | new SMTP extensions that might be useful to support." | 149 | new SMTP extensions that might be useful to support." |
| 162 | :type 'boolean | 150 | :type 'boolean |
| 163 | :version "21.1" | 151 | :version "21.1") |
| 164 | :group 'smtpmail) | ||
| 165 | 152 | ||
| 166 | (defcustom smtpmail-queue-index-file "index" | 153 | (defcustom smtpmail-queue-index-file "index" |
| 167 | "File name of queued mail index. | 154 | "File name of queued mail index. |
| 168 | This is relative to `smtpmail-queue-dir'." | 155 | This is relative to `smtpmail-queue-dir'." |
| 169 | :type 'string | 156 | :type 'string) |
| 170 | :group 'smtpmail) | 157 | |
| 158 | (defcustom smtpmail-servers-requiring-authorization nil | ||
| 159 | "Regexp matching servers that require authorization. | ||
| 160 | Normally smtpmail will try first to send emails via SMTP without | ||
| 161 | user/password credentials, and then retry using credentials if | ||
| 162 | the server says that it requires it. If the server name matches | ||
| 163 | this regexp, smtpmail will send over the credentials on the first | ||
| 164 | attempt." | ||
| 165 | :type '(choice regexp (const :tag "None" nil))) | ||
| 171 | 166 | ||
| 172 | ;; End of customizable variables. | 167 | ;; End of customizable variables. |
| 173 | 168 | ||
| @@ -679,6 +674,12 @@ Returns an error if the server cannot be contacted." | |||
| 679 | result | 674 | result |
| 680 | auth-mechanisms | 675 | auth-mechanisms |
| 681 | (supported-extensions '())) | 676 | (supported-extensions '())) |
| 677 | |||
| 678 | (when (and smtpmail-servers-requiring-authorization | ||
| 679 | (string-match-p smtpmail-servers-requiring-authorization | ||
| 680 | smtpmail-smtp-server)) | ||
| 681 | (setq ask-for-password t)) | ||
| 682 | |||
| 682 | (unwind-protect | 683 | (unwind-protect |
| 683 | (catch 'done | 684 | (catch 'done |
| 684 | ;; get or create the trace buffer | 685 | ;; get or create the trace buffer |