Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Python Shell CSS
Failed to load latest commit information.
doc Update
sphinx pretty up index page
.gitignore This is now a jekyll site
LICENSE Flask app connects to database en route Fail gracefully on bad DATABASE_URL
requirements.txt DRY up Database.find*


CryptoBot Email is an email bot that helps people learn how to use OpenPGP. You send CryptoBot a PGP-encrypted and signed email (probably using GnuPG) and it responds telling you how you do, and offering advice.

Getting Started

Start by copying into and editing it.

$ cp

Set all of these settings:

  • PGP_NAME: The name part of the user ID for for the bot's OpenPGP keypair
  • PGP_EMAIL: The email part of the user ID for for the bot's OpenPGP keypair. This should be the email address that users are expected to email.
  • GPG_HOMEDIR: The directory in which the bot's keyring will be stored (it will be created by the bot if it does not exist). This should be in a location that is writeable by the bot.
  • USE_MAILDIR: You can either use a Maildir or IMAP; set to False to use IMAP
  • MAILDIR: If you're using a Maildir, this is the path to it
  • IMAP_SERVER: The IMAP server to connect to, e.g.
  • IMAP_USERNAME: The IMAP username
  • IMAP_PASSWORD: The IMAP password
  • SMTP_SERVER: The SMTP server to connect to, e.g.
  • SMTP_USERNAME: The SMTP username
  • SMTP_PASSWORD: The SMTP password
  • DATABASE_URL: URL for the unsubscribe database

This is a Python project with some external dependencies. We recommend using virtualenv:

$ virtualenv env
$ . env/bin/activate
(env) $ pip install -r requirements.txt
(env) $ ./
# when you're done
(env) $ deactivate


To avoid exploitation as an automated spam cannon, cryptobot can optionally maintain a database of unsubscribers. It requires one additional setup step. After installing requirements, uncomment the DATABASE_URL in, and run

./ --setup

This will create the necessary database tables and generate a random salt for hashing email addresses. Once that's done, you can add emails to the database by running

./ --add

Alternatively you can run the included Flask app to serve a simple unsubscribe form for people to unsubscribe themselves.

./    # http://localhost:5000/unsubscribe

For simplicity, you can use an sqlite database, which is created as a normal file in the directory of your choosing, and does not incur any extra dependencies. However, for better concurrency handling, you may want to install and use postgresql, which will require the psycopg2 python module along with some additional system configuration:

sudo apt-get install postgresql
sudo -u postgres createuser -P -s -e cryptobot
createdb cryptobot -O cryptobot
sudo apt-get install postgresql-server-dev-9.1
. env/bin/activate
pip install psycopg

Dev Notes

On linux systems: if you get an error while trying to install requirements.txt, like "fatal error: Python.h: No such file or directory" $ sudo apt-get install python-dev

To run the tests:

$ ./

By default, the tests skip key generation, which can be slow and use up entropy. To include these tests, run:

$ ./ --slow

Relevant specs:

Something went wrong with that request. Please try again.