This Python script integrates with Microsoft Outlook to read the latest email in your inbox and uses OpenAI's GPT AI model to generate a draft response. The script then creates a draft email in Outlook with this AI-generated response.
- Retrieves the latest email from your Outlook inbox.
- Generates an AI response using OpenAI's GPT-3.5 model.
- Creates a draft email in Outlook with the AI response.
-
Install Python: Ensure you have Python installed on your machine. Download Python
-
Install Dependencies: Install the required Python libraries by running:
pip install win32com.client openai python-dotenv
-
Configure OpenAI API Key: Set your OpenAI API key in an
.env
file:OPENAI_API_KEY=your_api_key_here
-
Outlook Setup: Make sure you have Outlook installed and configured with your email account.
-
Run the Script: Execute the script with Python to start processing emails.
python ai_email_assistant.py
Once setup is complete, execute the script. It will:
- Access the latest email in your inbox.
- Use the email content to generate a draft response via OpenAI's model.
- Create a new draft email in Outlook with the suggested response.
Below is a brief overview of each main function:
get_latest_email_content()
: Retrieves the subject, body, and sender of the latest email from the Outlook inbox.
generate_ai_response(email_subject, email_body)
: Generates an AI response using the provided email subject and body.
create_draft_email(response, recipient, email_subject)
: Creates a draft email in Outlook with the specified response, recipient, and subject.
This project is released under the MIT License. This permissive license allows for free use, modification, and distribution of the software, provided that the original author is credited. For full license text, see LICENSE.md in this repository.
When using this AI Email Assistant, consider the following security aspects:
-
Email Privacy: The script interacts with your email data. Ensure you have the necessary permissions and understand the privacy implications of using such scripts with your email account.
-
API Key Security: Your OpenAI API key is sensitive information. Keep it secure and never expose it in public repositories or unsecured locations.
-
Data Handling: While the script does not store email content or responses, it does process potentially sensitive information. Be cautious of where and how the data is processed, and ensure that the systems running the script are secure.