Email Auto-ReplAI ✉️🤖 is a Python tool that uses AI to automate drafting responses to unread Gmail messages, streamlining email management tasks. It creates drafts for messages specifically addressed to the user, disregarding messages where the user is only CCed or BCCed. Additionally, the application does not generate drafts for messages from or reply-to a noreply or donotreply address and messages with a List-Unsubscribe header. The application can use either a local AI model or the OpenAI API based on your configuration.
To get started, you first need to pull the Docker image from the GitHub Container Registry. You can do this by running the following command in your terminal:
docker pull ghcr.io/rahb-realtors-association/email-autodrafts:latest
You need to provide your OpenAI API key and specify whether you want to use a local AI model or the OpenAI API. You also need to bind mount your settings.json
file into the Docker container.
You can do this by running the following command:
docker run -e OPENAI_API_KEY=<your_openai_api_key> -v /path/to/your/settings.json:/app/settings.json -v /path/to/your/credentials.json:/app/credentials.json -v /path/to/your/tocken.pickle:/app/token.pickle ghcr.io/rahb-realtors-association/email-autodrafts:latest
Please replace <your_openai_api_key>
with your actual OpenAI API key, /path/to/your/settings.json
with the actual path to your settings.json
file on your host system, and the same for credentials.json
and token.pickle
.
- Clone this repository to your local machine:
git clone https://github.com/RAHB-REALTORS-Association/email-autodrafts.git
cd email-autodrafts
- Install the required Python packages by running the following command in your terminal:
pip install -r requirements.txt
- Set up a project in the Google API Console, enable the Gmail API, and download the
credentials.json
file. For detailed instructions, please refer to the Google API Python Client's User Guide. - Place the
credentials.json
file in the same directory as your Python script. - Adjust the settings in
settings.json
to match your setup. You can specify the AI model and the Gmail scopes. - Set the
OPENAI_API_KEY
environment variable to your OpenAI API key. - Set the
USE_LOCAL
environment variable totrue
if you want to use a local AI model, orfalse
(or leave it unset) if you want to use the OpenAI API. - Run the script by executing the following command in your terminal:
python main.py
You can also add the --local
flag to use the local AI model, regardless of the USE_LOCAL
environment variable:
python main.py --local
The script performs the following steps in a loop:
- Connects to Gmail using OAuth 2.0. 🔒
- Fetches unread emails. 📥
- Filters emails based on the specified rules (directly addressed to user, no List-Unsubscribe header, and not from a noreply/donotreply address). 🧹
- Parses the filtered email content. 📝
- Sends the email content to either a local AI model or the OpenAI API, based on your configuration, to generate a response. 📤💬
- Creates a draft in Gmail with the generated response. 📝✉️
The script sleeps for an hour between each loop.
The script logs information and error messages to a file named app.log
. This can be used to monitor the script's operation and troubleshoot any issues.
This script is intended to be run locally on a user's machine. The user must be able to open a web browser on the machine to authorize the script with their Google account.
Contributions of any kind are very welcome, and would be much appreciated. For Code of Conduct, see Contributor Convent.
To get started, fork the repo, make your changes, add, commit and push the code, then come back here to open a pull request. If you're new to GitHub or open source, this guide or the git docs may help you get started, but feel free to reach out if you need any support.
If you've found something that doesn't work as it should, or would like to suggest a new feature, then go ahead and raise an issue on GitHub. For bugs, please outline the steps needed to reproduce, and include relevant info like system info and resulting logs.
This project is open sourced under the MIT license. See the LICENSE file for more info. 📜