2

I want to send multiple emails from Gnus. I have over 1000 addresses. I have found a great solution here: https://lists.gnu.org/archive/html/help-gnu-emacs/2014-04/msg00584.html

(defun message-send-and-exit-multiple ()
  (interactive)
  (let ((addresses 
         (split-string 
          (message-fetch-field "All")
          "," t)))
    (while addresses
      (let ((address (car addresses)))
        (setq addresses (cdr addresses))
        (message-remove-header "To")
        (message-add-header (format "To: %s" address))
        (if addresses
            (message-send)
          (message-send-and-exit))))))

But Emacs asks me for every email: "Already sent message via mail; resend? (y or n)". So how I can automate the process? Also maybe it would be a good idea to add some sleep between sending emails? Like send 50 emails wait some time then send another?

2 Answers 2

3

There is a easy and generic solution.

You are actually calling message-send which calls y-or-n-p to ask you confirm.

So you want to automatically answer "Yes" when being asked the question "Already sent message via mail; resend? (y or n)".

Here is code,

(defvar my-default-yes-no-answer nil
    "Usage: (setq my-default-answer '(t . \"question1 pattern\"))")
(defadvice y-or-n-p (around y-or-n-p-hack activate)
  (let* ((prompt (car (ad-get-args 0))))
    (message "prompt=%s" prompt)
    (cond
     ((and my-default-yes-no-answer
           (consp my-default-yes-no-answer )
           (string-match-p (cdr my-default-yes-no-answer) prompt))
      (setq ad-return-value (car my-default-yes-no-answer)))
     (t
      ad-do-it))))

Usage is simple. Only one liner, (setq my-default-yes-no-answer '(t . "Already sent message vial mail")).

1
  • 1
    Note that defadvice is the old way of writing function advice, made obsolete by nadvice.el. See (elisp) Porting Old Advice.
    – Basil
    Commented Apr 2, 2020 at 9:20
3

As usual, Gnus has a configuration variable for this: message-shoot-gnksa-feet, which you can M-x customize to enable the multiple-copies feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.