There are multiple ways you can achieve this. Reading your question I see two main requirements
1) Parsing a csv file and getting the list of emails from it
2) Sending out emails to the list of emails retrieved without recipients seeing other recipients email address
For first requirement I would suggest you to use pcsv. Below is an example of of using the library
(require 'pcsv)
(defun my-get-emails-from-csv (file &optional file-has-header-p)
(let* ((csv (pcsv-parse-file file))
;; If csv file has header strip the first element of the list
(emails (if file-has-header-p (cdr csv) csv)))
;; Go through the csv entries and format them for mu4e
(mapcar (lambda (email) (format "%s <%s>"
;; Remove any , in names
(replace-regexp-in-string "," "" (cadr email))
(car email)))
emails)))
The above function will parse the given file and return a list of emails of the format user <email>
.
Using this you can define an mail abbrev using define-mail-abbrev
like so
(define-mail-abbrev "MyClass" (string-join (my-get-emails-from-csv "<path-to-csv>" t) ", "))
For the second requirement you will have to use the BCC
header. Please also note that most (not all) email implementations hide the recipients so please research before using this.
In mu4e
while composing a message you can do M-xmail-bcc
RET this will add a bcc
header, you can type your alias MyClass
and hit SPC and it will be expanded to the aliased entries. You might also want to add yourself to the To:
field.
Since you have the basic building blocks, you can define custom commands that do what you want, one such example is below, it reads the path to a csv
file (it assumes file is in the format specified in your question) from the user and inserts the emails from the file in the BCC
field.
(defun my-mail-to-people-from-file (file)
(interactive "fRead emails from file: ")
(save-excursion
(mail-bcc)
;; Read the emails from the CSV file and insert them
(insert (string-join (my-get-emails-from-csv file t) ", "))))
In case string-join is not defined in your emacs use following to define it
(unless (fboundp 'string-join)
(defun string-join (strings &optional separator)
"Join all STRINGS using SEPARATOR."
(mapconcat 'identity strings separator)))