Simple Python Email Server

1 minute read

For a side project I wanted to be allow users to be able to send me emails but I didn’t want to use a third party service or have my email in a mailto in the client so I made this small email api.

email-server

Set up

Create a virtual environment and install the packages:

virtualenv venv;

source venv/bin/activate;

pip install -r requirements.txt

Follow this guide to create oauth2 gmail account credentials.

Open the make_credentials.py script and replace YOUR_EMAIL_HERE with the gmail email you want to use. Run the script to have yagmail create your oauth2 gmail client credentials file.

python3 scripts/make_credentials.py

Now you can run the main application!

./run.sh

Sending an email

Hit the /email endpoint with a POST request using something like the example JSON below:

{
    "from": "test@test.com",
    "subject": "This is a test email",
    "content": "Here is the email content!"
}

Deploying to Heroku

If you have a Heroku account this email server can be deployed there using the shell deployment scripts in the scripts directory. Install the Heroku cli and log in. Next change the APP_NAME_HERE values from the shell scripts in the scripts directory with your application name. Lastly follow the steps below:

Build the app

./scripts/build-app.sh

Then release it

./scripts/release-app.sh

Comments