The Complete Computing Environment

Sending Mail in Gnus


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 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. This home-manager snippet doesn't work since I use SSH tunnels for connection and I can't specify that in the home-manager module.


  programs.msmtp.enable = true; = {
    address = "";
    realName = "Ryan Rix (rrix)";

    aliases = [ "" "" ];
    userName = "";

    primary = true;

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

    smtp = {
      host = "";
      port = 587;
      tls = { useStartTls = true; };

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
                        ((executable-find "msmtp") (executable-find "msmtp"))
                        ((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 ""
         (gnus-message-archive-group "nnimap+maildir:fastmail/Sent")
          (address "")
          (name "Ryan Rix")
          (body "")
          (eval (setq message-sendmail-extra-arguments '("-a" "fastmail")))
          (signature-file "~/sync/personal-sig")
          (user-mail-address "")))
         (gnus-message-archive-group "nnimap+maildir:crdigital/[Gmail]/Sent Mail")
          (address "")
          (name "Ryan Rix")
          (body "")
          (eval (setq message-sendmail-extra-arguments '("-a" "crdig")))
          (signature-file "~/sync/work-sig")
          (user-mail-address "")))

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)
        (let* ((from
                  (message-fetch-field "from")))
                 ((string-match "" from) "fastmail")
                 ((string-match "" from) "fastmail")
                 ((string-match "" from) "crdig")
                 (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.