Function: smtpmail-query-smtp-server

smtpmail-query-smtp-server is a byte-compiled function defined in smtpmail.el.gz.

Signature

(smtpmail-query-smtp-server)

Documentation

Query for an SMTP server and try to contact it.

If the contact succeeds, customizes and saves smtpmail-smtp-server and smtpmail-smtp-service. This tries standard SMTP ports, and if none works asks you to supply one. If you know that you need to use a non-standard port, you can set smtpmail-smtp-service in advance. Returns an error if the server cannot be contacted.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/smtpmail.el.gz
(defun smtpmail-query-smtp-server ()
  "Query for an SMTP server and try to contact it.
If the contact succeeds, customizes and saves `smtpmail-smtp-server'
and `smtpmail-smtp-service'.  This tries standard SMTP ports, and if
none works asks you to supply one.  If you know that you need to use
a non-standard port, you can set `smtpmail-smtp-service' in advance.
Returns an error if the server cannot be contacted."
  (let ((server (read-string "Outgoing SMTP mail server: "))
	(ports '(25 587))
	stream port prompted)
    (when (and smtpmail-smtp-service
	       (not (member smtpmail-smtp-service ports)))
      (push smtpmail-smtp-service ports))
    (while (and (not smtpmail-smtp-server)
		(setq port (pop ports)))
      (if (not (setq stream (condition-case ()
				(open-network-stream "smtp" nil server port)
			      (quit nil)
			      (error nil))))
	  ;; We've used up the list of default ports, so query the user.
	  (when (and (not ports)
		     (not prompted))
	    (push (read-number (format "Port number to use when contacting %s? "
				       server))
		  ports)
	    (setq prompted t))
	(customize-save-variable 'smtpmail-smtp-server server)
	(customize-save-variable 'smtpmail-smtp-service port)
	(delete-process stream)))
    (unless smtpmail-smtp-server
      (error "Couldn't contact an SMTP server"))))