Function: smtpmail-send-queued-mail

smtpmail-send-queued-mail is an autoloaded, interactive and byte-compiled function defined in smtpmail.el.gz.

Signature

(smtpmail-send-queued-mail)

Documentation

Send mail that was queued as a result of setting smtpmail-queue-mail.

Probably introduced at or before Emacs version 28.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/mail/smtpmail.el.gz
;;;###autoload
(defun smtpmail-send-queued-mail ()
  "Send mail that was queued as a result of setting `smtpmail-queue-mail'."
  (interactive)
  (with-temp-buffer
    ;; Get index, get first mail, send it, update index, get second
    ;; mail, send it, etc...
    (let (file-data file-elisp
          (qfile (expand-file-name smtpmail-queue-index-file
                                   smtpmail-queue-dir))
          (stored (cons 'smtpmail-recipient-address-list
                        smtpmail--stored-queue-variables))
          smtpmail-recipient-address-list
          (smtpmail-smtp-server smtpmail-smtp-server)
          (smtpmail-stream-type smtpmail-stream-type)
          (smtpmail-smtp-service smtpmail-smtp-service)
          (smtpmail-smtp-user smtpmail-smtp-user)
	  result)
      (insert-file-contents qfile)
      (goto-char (point-min))
      (while (not (eobp))
	(setq file-data (buffer-substring (point) (line-end-position)))
	(setq file-elisp (concat file-data ".el"))
        (let ((coding-system-for-read 'utf-8))
          (with-temp-buffer
            (insert-file-contents file-elisp)
            (let ((form (read (current-buffer))))
              (when (or (not (consp form))
                        (not (eq (car form) 'setq))
                        (not (consp (cdr form))))
                (error "Unexpected code in %S: %S" file-elisp form))
              (cl-loop for (var val) on (cdr form) by #'cddr
                       when (memq var stored)
                       do (set var val)))))
	;; Insert the message literally: it is already encoded as per
	;; the MIME headers, and code conversions might guess the
	;; encoding wrongly.
	(with-temp-buffer
	  (let ((coding-system-for-read 'no-conversion))
	    (insert-file-contents file-data))
          (let ((smtpmail-mail-address
                 (or (and mail-specify-envelope-from
                          (save-restriction
                            ;; Only look at the headers when fetching the
                            ;; envelope address.
                            (message-narrow-to-headers)
                            (mail-envelope-from)))
                     user-mail-address)))
            (if (not smtpmail-recipient-address-list)
                (error "Sending failed; no recipients")
              (when (setq result (smtpmail-via-smtp
				  smtpmail-recipient-address-list
				  (current-buffer)))
		(error "Sending failed: %s"
                       (smtpmail--sanitize-error-message result))))))
	(delete-file file-data)
	(delete-file file-elisp)
        (delete-region (line-beginning-position) (line-beginning-position 2)))
      (write-region (point-min) (point-max) qfile))))