Sending Mail in Gnus

Tags: 

I go to great lengths to talk about receiving messages in Email and News and Information Pipelines, but I do not spend a lot of energy in that document discussing out-bound communication. This is because I don't often use email for outbound communication these days, at least as the sole medium. I believe email and similar tools can be effective communication medium for multi-person technical projects, but I am not participating in any of those right now. Off in my own little Cathedral as I am, I find myself mostly sending emails about bills, to my landlord, with my financial advisers and my mentors – there are few people for whome email is my primary form of communication.

But it's a fine form of communication, especially for those of us who do not actively participate in the Facebook news feed ecosystem, and Story Culture, we're often found without ways to communicate with our kin and our tribe. Email is still universal because of those bill collectors, landlords, and other institutions, and I intend to take advantage of that as a way to communicate with those kin. I find that even though I no longer absorb family updates through newsfeed osmosis, I do hear from folks in response to my emails, so I intend to continue working that in to the design of my websites and the Arcology: Every page on this wiki should be shareable via email1. I should be able to curate groups of interest and contact them about my work directly.

I am uninterested in running the plumbing required to communicate over email. I am currently an ambivalent user of Fastmail.com. It's a fine service, upstanding folks, and they provide good open standards support for things like Calendaring, a contact book, and file hosting, so that it'd absolutely function as a suitable set of services to replace a Google or iCloud account for many people, with a much healthier financial model to boot. But I don't really use a lot of that stuff, instead I host a Nextcloud server on my Fontkeming host. And so I use them as an Email provider, and they do provide email quite well enough. But something about my spam filters went sicko a while ago, and I've struggled to reign it in, i think Fastmail's filtering isn't at all prepared to deal with my wildcard inboxes2. I continue to use it because it works well enough, but a very light mail-only service would be quite nice. Something with a command line client preconfigured would be very desirable, too, for some reason.

I use msmtp in the meantime, it is a forwarding mail agent which can be configured to route email to different accounts, so I could have it send mail to fastmail for any of my personal accounts, and trivially reintroduce configuration for an email account tied to an employer's domain or of a nonprofit that I join. My msmtprc file is kept out of source-control until such a time as I can document it without leaking my password. Real casual shit, here.

accounts.email.accounts.fastmail = {
  address = "ryan@whatthefuck.computer";
  realName = "Ryan Rix (rrix)";

  aliases = [ "ry@n.rix.si" "rrix@fastmail.com" ];
  userName = "rrix@fastmail.com";

  primary = true;

  passwordCommand = "pass show fastmail_email_app";

  msmtp = {
    enable = true;
    extraConfig = "logfile /tmp/msmtp.log";
  };

  smtp = {
    host = "mail.messagingengine.com";
    port = 587;
    tls = { useStartTls = true; };
  };
};
- name: msmtp is installed
  dnf:
    state: installed
    name: msmtp
  when: ansible_pkg_mgr == "dnf"
  tags:
  - msmtp

- name: msmtp is installed
  shell:
    creates: /data/data/com.termux/files/usr/bin/msmtp
    cmd: pkg install -y msmtp
  when: ansible_pkg_mgr == "unknown"
  tags:
  - msmtp

- name: msmtp is installed
  fail:
    msg: unimplemented
  when: ansible_pkg_mgr == "apt"
  tags:
  - msmtp

The Emacs messaging subsystem can be configured to use msmtp command line arguments, it's quite flexible. I believe that message-sendmail-f-is-evil will prevent Emacs from including the user-mail-address variable in the command line arguments. Instead, msmtp will by asked by --read-envelope-from to read the "From" header out of the body to set the canonical sender, which means I can just set it by editing the header in the message-mode browser.

(setq message-sendmail-f-is-evil 't
      message-sendmail-extra-arguments '("--read-envelope-from")
      message-send-mail-function 'message-send-mail-with-sendmail
      sendmail-program (cond
                        ((file-exists-p "/usr/local/bin/msmtp") "/usr/local/bin/msmtp")
                        ((file-exists-p "/usr/bin/msmtp") "/usr/bin/msmtp")))

I default to my personal mail account, and that has led to mistakes in the past with sending work email from my personal email account. But it was always something quickly noticed, when I got back a bounce email from the private Google Groups that were included in the message recipients.

This needs to be set up in two ways:

The first way that this needs to be set is using customizing the Group Parameters for groups matching appropriate regular expressions. Setting this will cause new messages created while I am in a group summary buffer will be pre-configured to have the correct sender address, signature, etc. Adding rules is simple because new accounts will be in their own sub-folders of the maildir, the central server providing a suitable proxy, keeping my endpoints from having to worry about sharing passwords for service accounts.

(setq message-sendmail-extra-arguments '("-a" "fastmail")
      mail-host-address "whatthefuck.computer"
      gnus-parameters
      '((".*fastmail.*"
         (gnus-message-archive-group "nnimap+maildir:fastmail/Sent")
         (posting-style
          (address "ryan@whatthefuck.computer")
          (name "Ryan Rix")
          (body "")
          (eval (setq message-sendmail-extra-arguments '("-a" "fastmail")))
          (signature-file "~/sync/personal-sig")
          (user-mail-address "ryan@whatthefuck.computer")))))

The second way is with this function cg-feed-msmtp which I found on the internet ages ago. This function will look for the value I have set as my From or has been filled automatically by the above posting-style guidances will be set as the account to send.

(defun cg-feed-msmtp ()
  (if (message-mail-p)
      (save-excursion
        (let* ((from
                (save-restriction
                  (message-narrow-to-headers)
                  (message-fetch-field "from")))
               (account
                (cond
                 ((string-match "ryan@whatthefuck.computer" from) "fastmail")
                 ((string-match "ry@n.rix.si" from) "fastmail")
                 (t "fastmail"))))
          (setq message-sendmail-extra-arguments (list '"-a" account))))))

(setq message-sendmail-envelope-from 'header)
(add-hook 'message-send-mail-hook 'cg-feed-msmtp)

Only the tallest Rube Goldberg machines, my friends.

Footnotes


  1. this is a Knowledge Management principle↩︎

  2. any mail to @rix.si or @whatthefuck.computer accounts all go to the same inbox… this kills the bayesian filter.↩︎


This is Referenced

''

in "CCE on Termux"

in "The Complete Computing Environment"

in "Gnus"

in "Generate a Dynamic Home Manager Configuration"