This is a simple email assistant application that reads incoming emails, processes them using the OpenAI GPT-3.5 API, and sends responses. It uses Node.js, IMAP for reading emails, Nodemailer for sending emails, and the OpenAI API for natural language processing.
- Node.js v14.20.0 or later
- A Gmail account with "Allow less secure apps" enabled or an App Password generated
- OpenAI API Key (You will be provided with the necessary information)
To use this application with your Gmail account, you need to enable "Allow less secure apps" or generate an App Password. Follow the steps below:
- Sign in to your Google Account.
- Go to the Less secure apps page.
- Turn on "Allow less secure apps."
- Sign in to your Google Account.
- Go to the App passwords page.
- Select "Mail" as the app and "Other (Custom name)" as the device.
- Enter a custom name (e.g., "Email Assistant") and click "Generate."
- Copy the generated 16-character App Password and use it as the
PASSWORD
in your.env
file.
Important: Do not share your App Password or use it for any other purpose.
To obtain your OpenAI API Key, follow these steps:
- Go to the OpenAI API Keys page.
- Sign in with your OpenAI account or create one if you don't have it already.
- After signing in, you will see a list of your API keys. If you don't have any API keys yet, click the "Create" button to generate one.
- Copy the secret API key (it starts with
sk-
) and paste it into theOPENAI_API_KEY
variable in your.env
file.
Important: Do not share your API key with others or expose it in the browser or other client-side code. In order to protect the security of your account, OpenAI may automatically rotate any API key that they've found has leaked publicly.
- Clone this repository and navigate to the project directory:
git clone https://github.com/tgeant/gmail-chatgpt-assistant.git
cd gmail-chatgpt-assistant
- Install the required dependencies:
npm install
- Create a
.env
file in the root directory of the project and add the necessary environment variables:
EMAIL=myemail@gmail.com
PASSWORD=my_password
OPENAI_API_KEY=my_api_key
SYSTEM_PROMPT=You are a helpful assistant.
Replace myemail@gmail.com
with your Gmail address, my_password
with your Gmail password or App Password, and my_api_key
with your OpenAI API key. The SYSTEM_PROMPT
variable contains the system message used to set the context for the GPT-3.5 API.
You can run the application using either npm
or Docker
.
To start the application using npm, run the following command:
npm start
- Build the Docker image:
docker build -t email-assistant .
- Run the Docker container:
docker run -d --name email-assistant --env-file .env -v $(pwd):/app email-assistant sh -c "npm install && npm start"
This will run the container in the background, use the environment variables from the .env
file, and mount the current directory to the container's working directory.
-
Make sure the
docker-compose.yml
file is in the project root. -
Run the Docker Compose:
docker-compose up -d
This will run the container in the background using the configuration from the docker-compose.yml
file.
This project is licensed under the MIT License.