:group 'mail)
-(defvar smtpmail-default-smtp-server nil
+(defcustom smtpmail-default-smtp-server nil
"Specify default SMTP server.
-This only has effect if you specify it before loading the smtpmail library.")
+This only has effect if you specify it before loading the smtpmail library."
+ :type '(choice (const nil) string)
+ :group 'smtpmail)
(defcustom smtpmail-smtp-server
(or (getenv "SMTPSERVER") smtpmail-default-smtp-server)
(defcustom smtpmail-stream-type nil
"Connection type SMTP connections.
-This may be either nil (plain connection) or `starttls' (use the
-starttls mechanism to turn on TLS security after opening the
-stream)."
+This may be either nil (possibly upgraded to STARTTLS if
+possible), or `starttls' (refuse to send if STARTTLS isn't
+available), or `plain' (never use STARTTLS).."
:version "24.1"
:group 'smtpmail
- :type '(choice (const :tag "Plain" nil)
- (const starttls)))
+ :type '(choice (const :tag "Possibly upgrade to STARTTLS" nil)
+ (const :tag "Always use STARTTLS" starttls)
+ (const :tag "Never use STARTTLS" plain)))
(defcustom smtpmail-sendto-domain nil
"Local domain name without a host name.
(defun smtpmail-try-auth-methods (process supported-extensions host port
&optional ask-for-password)
+ (setq port
+ (if port
+ (format "%s" port)
+ "smtp"))
(let* ((mechs (cdr-safe (assoc 'auth supported-extensions)))
(mech (car (smtpmail-intersection mechs smtpmail-auth-supported)))
(auth-source-creation-prompts
(secret . "SMTP password for %u@%h: ")))
(auth-info (car
(auth-source-search
- :max 1
:host host
- :port (if port
- (format "%s" port)
- "smtp")
+ :port port
+ :max 1
:require (and ask-for-password
'(:user :secret))
:create ask-for-password)))
(save-function (and ask-for-password
(plist-get auth-info :save-function)))
ret)
+ (when (and user
+ (not password))
+ ;; The user has stored the user name, but not the password, so
+ ;; ask for the password, even if we're not forcing that through
+ ;; `ask-for-password'.
+ (setq auth-info
+ (car
+ (auth-source-search
+ :max 1
+ :host host
+ :port port
+ :require '(:user :secret)
+ :create t))
+ password (plist-get auth-info :secret)))
(when (functionp password)
(setq password (funcall password)))
(cond
(and mail-specify-envelope-from
(mail-envelope-from))
user-mail-address))
+ (coding-system-for-read 'binary)
+ (coding-system-for-write 'binary)
response-code
process-buffer
result
;; If we couldn't access the server at all, we give up.
(unless (setq process (car result))
- (throw 'done "Unable to contact server"))
+ (throw 'done (if (plist-get (cdr result) :error)
+ (plist-get (cdr result) :error)
+ "Unable to contact server")))
;; set the send-filter
(set-process-filter process 'smtpmail-process-filter)