Shell scripts for generating random mail aliases (https://hakon.gylterud.net/newmail/)
root
% newmail
% HÃ¥kon Robbestad Gylterud
`newmail` is a simple script to generate random e-mail aliases
from the command line for OpenSMTPD on OpenBSD. I wrote this to
avoid having to give out my real e-mail address to every place
which requires registration.
`whichemail` queries the aliases for previously generated e-mails.
## Requirements
- A working mail server.
- [`apg`](https://web.archive.org/web/20160301165817/http://www.adel.nursat.kz/apg/)^[`pkg_add apg`],
for reasonable looking random addresses,
available as a package as an [OpenBSD package](https://man.openbsd.org/packages)^[`pkg_add plan9port`].
- `rc` and `ssam` from plan9port also an OpenBSD package.
## Installation
- [newmail](https://hub.darcs.net/gylterud/newmail/raw-file/newmail),
create new aliases
- [whichmail](https://hub.darcs.net/gylterud/newmail/raw-file/whichmail), query existing aliases
Download and copy the above scripts to
- `/usr/local/bin/newmail` and
- `/usr/local/bin/whichmail`.
**Edit the configuration variables at the top of the script**. Remember to read through the
source files to understand what they do. Then consider applying a few conveniences to
your system configuration.
The following line in `/etc/doas.conf` enables users^[change the group to what-ever fits
your system] to run it:
~~~~~
permit nopass :users as root cmd newmail
~~~~~
For ease of use, I also added the following to `/etc/skel/.profile`
and current users `$HOME/.profile`:
~~~~~
alias newmail='doas newmail'
~~~~~
## Usage
To get a new e-mail address, you simply run `newmail`, with
an optional argument identifying the site you associate with
this address:
~~~~~
user@example.com $ newmail hub.darcs.net
pemovrypur@example.com
~~~~~
And if you later forgot which one you had generated:
~~~~~
user@example.com $ whichmail hub.darcs.net
pemovrypur@example.com
~~~~~
## How does it work?
After running `newmail`, the following lines have been added
to `/etc/mail/aliases`:
~~~~~
# f5cb7a763186dea37d3f98f7ce9bae6a9449587892acd69f89f88bcae71e694f
pemovrypur: user
~~~~~
The SHA256 in the comment has identifies the user and associated site, and is
used by `whichmail` to look up the addresses.
The changes are loaded by smtpd, and `user` will receive e-mail sent
to pemovrypur@example.com.
## Source
The scripts are written in `rc`
(the shell of [Plan9port](https://github.com/9fans/plan9port).
You can easily port them to any other shell your self. The
`newmail` script itself is roughly ten lines.
- The source repository resides on [DarcsHub](https://hub.darcs.net/gylterud/newmail/)