:group 'smtp)
(defcustom smtp-server (or (getenv "SMTPSERVER") smtp-default-server)
- "*The name of the host running SMTP server."
- :type '(choice (const nil) string)
+ "*The name of the host running SMTP server. It can also be a function
+called from `smtp-via-smtp' with arguments SENDER and RECIPIENTS."
+ :type '(choice (string :tag "Name")
+ (function :tag "Function"))
:group 'smtp)
(defcustom smtp-service "smtp"
(error "Cannot generate valid FQDN. Set `smtp-local-domain' correctly.")))))
(defun smtp-via-smtp (sender recipients smtp-text-buffer)
- (let (process response extensions)
+ (let ((server (if (functionp smtp-server)
+ (funcall smtp-server sender recipients)
+ smtp-server))
+ process response extensions)
(save-excursion
(set-buffer
(get-buffer-create
- (format "*trace of SMTP session to %s*" smtp-server)))
+ (format "*trace of SMTP session to %s*" server)))
(erase-buffer)
(make-local-variable 'smtp-read-point)
(setq smtp-read-point (point-min))
(unwind-protect
(catch 'done
(setq process (open-network-stream-as-binary
- "SMTP" (current-buffer) smtp-server smtp-service))
+ "SMTP" (current-buffer) server smtp-service))
(or process (throw 'done nil))
(set-process-filter process 'smtp-process-filter)
extensions)
(setq extension-lines (cdr extension-lines)))))
- ;; ONEX --- One message transaction only (sendmail extension?)
+ ;; ONEX --- One message transaction only (sendmail extension?)
(if (or (memq 'onex extensions)
(memq 'xone extensions))
(progn
(>= (car response) 400))
(throw 'done (car (cdr response))))))
- ;; VERB --- Verbose (sendmail extension?)
+ ;; VERB --- Verbose (sendmail extension?)
(if (and smtp-debug-info
(or (memq 'verb extensions)
(memq 'xvrb extensions)))
(>= (car response) 400))
(throw 'done (car (cdr response))))))
- ;; XUSR --- Initial (user) submission (sendmail extension?)
+ ;; XUSR --- Initial (user) submission (sendmail extension?)
(if (memq 'xusr extensions)
(progn
(smtp-send-command process "XUSR")
process
(format "MAIL FROM:<%s>%s%s"
sender
- ;; SIZE --- Message Size Declaration (RFC1870)
+ ;; SIZE --- Message Size Declaration (RFC1870)
(if (memq 'size extensions)
(format " SIZE=%d"
(save-excursion
;; those two bytes anyway:
2)))
"")
- ;; 8BITMIME --- 8bit-MIMEtransport (RFC1652)
+ ;; 8BITMIME --- 8bit-MIMEtransport (RFC1652)
(if (and (memq '8bitmime extensions)
smtp-use-8bitmime)
" BODY=8BITMIME"
(not (integerp (car response)))
(>= (car response) 400))
(throw 'done (car (cdr response))))
-
+
;; RCPT TO:<recipient>
(while recipients
(smtp-send-command process
(not (integerp (car response)))
(>= (car response) 400))
(throw 'done (car (cdr response)))))
-
+
;; DATA
(smtp-send-command process "DATA")
(setq response (smtp-read-response process))