2

I have a file ~/foo/contacts.csv whose first two columns look like

Student ID,Student Name
firstID@foo.org,"Lennon, John"
secondID@foo.org,"McCartney, Paul"
thirdID@foo.org,"Harrison, George"
fourthID@foo.org,"Starr, Ringo"

In actuality, the file has dozens of lines and several other columns. This file is updated every day (people are added and others are deleted).

I'd like to be able to e-mail every person on this list using mu4e. Ideally this would be done so that each recipient cannot see the identities of the other receipts.

Does mu4e have the capability to read my csv file so I can easily email the entire list under the pseudoname My Class?

Brian Fitzpatrick
  • 2,265
  • 1
  • 17
  • 40

2 Answers2

2

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-bccRET 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)))
Iqbal Ansari
  • 7,468
  • 1
  • 28
  • 31
1

AFAIK there is no built-in feature in mu4e to achieve this. However, message-mode does support mail aliases.

The procedure (define-mail-abbrev NAME DEFINITION &optional FROM-MAILRC-FILE) could be used to define a name "My Class" that expands to the result of parsing the CSV file into a comma-separated list of strings. When composing a message, type "My Class" and run M-x expand-abbrev to expand the mail alias.

The part that takes some effort is to parse the CSV file. You also need to remember to do re-evaluate the procedure that creates the abbreviation from the result of parsing the CSV.