This Python script automates email responses using OpenAI's GPT model and Gmail API. It fetches unread emails, generates AI-driven replies, and sends responses automatically.
- Authenticate with Gmail API.
- Fetch unread emails from the inbox.
- Generate AI-based responses using OpenAI's GPT model.
- Send replies to the original sender.
- Mark emails as read after responding.
- Python 3.x installed
- A Google Cloud project with Gmail API enabled
- OpenAI API key
- Required Python packages installed
-
Clone this repository:
git clone https://github.com/your-repo/ai-email-responder.git cd ai-email-responder -
Install dependencies:
pip install -r requirements.txt
-
Set up Google API credentials:
- Enable Gmail API in Google Cloud Console.
- Download
credentials.jsonand place it in the project folder.
-
Set up OpenAI API key:
- Create a
.envfile and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key
- Create a
Run the script with:
python main.py- Authenticates with Gmail using OAuth 2.0.
- Fetches unread emails.
- Uses GPT model to generate responses.
- Sends replies and marks emails as read.
- Modify
SCOPESto change Gmail permissions. - Adjust
generate_response()to customize AI behavior.
- Keep
credentials.jsonandtoken.jsonsecure. - Avoid exposing API keys in public repositories.
MIT License