Email Configuration for plan9 Acme on OpenBSD

Aaron Poffenberger
akp@hypernote.com

Following are steps for configuring email for plan9 Acme.

It was not hard to setup, but it took too long. I never found one page that covered everything from reading, to sending, to saving copies of outgoing mail. I had to read a lot of man pages, online posts, and source code to get everything working.

My hope is this post serves as one page that covers all the steps for configuring email for Acme.

Let me know if I've missed anything.

Overview

This post is focused on how to make it work, not why it works. Perhaps a future post will discuss what's going on under the hood.

The key things to understand are:

The steps are slightly OpenBSD centric (6.3-current as of this writing), but easily adapted to other platforms that run plan9port.

The steps are also specific to reading email hosted by an IMAP server. POP3 should be similar. See the man pages for factotum(4) and upasfs(4).

I don't use the plan9 mailer. I replace it with msmtp(1), which is a handy SMTP client that behaves a lot like sendmail(8).

For more details about Mail, see $PLAN9/src/cmd/acme/mail/readme, and $PLAN9/src/cmd/acme/mail/*.c. I've also included a Resources section at the end.

Install

$ cd $PLAN9/src/cmd/upas/
  $ doas mk install
  $ cd nfs
  $ doas mk install

Read Email

  1. Start plumber(4) and factotum(4):

     $ 9 plumber
       $ 9 factotum
  2. Add credentials:

     # !password? tells factotum to prompt for password
       $ 9 factotum -g 'proto=pass service=imap server=mail.example.org \
         user=user@example.org !password?'
  3. Start mailfs:

     # stunnel is required by mailfs for tls connections
       $ doas pkg_add -i stunnel
    
       # -t = use tls
       $ 9 mailfs -t mail.example.org
  4. Middle-click Mail in Acme to read email

Send Email

  1. Install msmtp from ports for sending,

  2. Configure $HOME/.msmtprc:

     $ cat $HOME/.msmtprc
       # Set default values for all following accounts.
       logfile ~/no_bak/.cache/msmtp.log
    
       defaults
           auth on
           port 465
           tls on
    
       # example.org
       # store password in ~/.netrc
       # or use password directive here
       account example
           host smtps.example.org
           from user@example.org
           user user@example.org
           # password supersekret
  3. Create $HOME/mail/pipefrom:

     $ cat $HOME/mail/pipefrom
       #!/bin/sh
    
       cat /dev/stdin | msmtp -f user@example.org $@
  4. Create $HOME/mail/headers:

     # Necessary because otherwise marshal(1) will use your
       # $USER@hostname an environment variable called upasname
       # overrides the From: value in $HOME/mail/headers
    
       $ cat $HOME/mail/headers
       From: My Real Name <user@example.org>
  5. Middle-click Mail in the tag bar for the mail browser, Reply or middle-sweep Reply All to send email.

    You have to add your own Subject and To lines:

     To: user1@example.org
       To: user2@example.org
       Subject: Test Email
       Include: <path_to_file>
       Attach: <path_to_file>
    
       This is a test.
    
       Notice I didn't put a "From:" line above. My $HOME/mail/headers
       file will take care of that.
    
       Include: file places a copy of file in the message as an
                inline MIME attachment.
       Attach: file places a copy of file in the message as a regular
               MIME attachment.
  6. Middle-click Post to send.

About Outgoing Email

Mail always writes outgoing email in $HOME/mail/outgoing (if it exists), regardless of whether you're using IMAP.

I'm working on a patch to write the mail to an IMAP folder. I'll post something on the blog when it's ready.

For now, make sure you touch(1) $HOME/mail/outgoing, otherwise your outbound email will not be saved.

Another option would be to add a "Bcc:" header to yourself in $HOME/mail/headers.

Miscellaneous

msmtp(1) can be configured with multiple SMTP servers, selecting the correct server based on the sender, or a command line value, but there's no way to set the "From:" header while writing an email. Mail seems to strip it.

Perhaps I'll write a patch for that as well.

Resources

Acme