This Python script automates the process of logging into a Gmail inbox, checking for unread emails, and printing out important details such as the sender, subject, and body in the terminal. I built this project to learn more about working with email protocols like IMAP and using environment variables to securely manage sensitive data.
- Logs into Gmail securely using credentials stored in a
.envfile. - Searches for unread (unseen) emails and displays key details.
- Prints sender, subject, and body in the terminal.
- Easy to customize and expand!
- Python 3
imaplib(for email access)email(to handle email parsing)python-dotenv(for managing environment variables securely)
-
Clone the repo
git clone https://github.com/yourusername/email-automation.git cd email-automation
-
Create and activate a virtual environment (optional but recommended)
python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Create a
.envfile In the root of the project, create a.envfile and add your credentials:EMAIL=[email protected] PASSWORD=your_app_password IMAP_SERVER=imap.gmail.com
⚠️ Important: Use a Gmail App Password, not your real Gmail password. You can generate an App Password here. -
Run the script
python email_automation.py
If Amazon Q was involved in this project, it could:
- Help explain the technical side of how IMAP works and offer suggestions for making the process more efficient.
- Suggest adding features like scheduling automatic email responses or making the script run asynchronously.
- Assist in securing secrets even more, perhaps using AWS Secrets Manager for safer storage of credentials.
To ensure your .env file isn’t uploaded to GitHub, make sure to add this line to your .gitignore:
.env
This project was created by me, Hanan Nasir – @hann2004
This project is intended for educational/demo purposes and has been submitted to the Amazon Q "Quack the Code" Challenge.