A powerful command-line interface for managing multiple Gmail accounts, built with Python.
Welcome to the Gmail Multi-Account CLI! This tool is designed to help you efficiently manage multiple Gmail accounts from the command line. Whether you need to check emails, send messages, or organize your inbox, this CLI provides a simple and intuitive interface to handle all your Gmail needs. With support for multiple accounts, you can easily switch between different Gmail accounts without logging in and out repeatedly.
- Features
- Requirements
- Installation
- Setting Up Gmail "Secure App Access"
- Usage
- Configuration
- Troubleshooting
- Contributing
- License
- Glossary
- Manage multiple Gmail accounts from the command line
- Read, send, and forward emails
- View new and older emails
- Colorful and user-friendly interface
- Secure handling of account credentials
- Go to your Google Account's App Passwords page: https://myaccount.google.com/apppasswords
- Select "Mail" and "Other (Custom name)" from the dropdowns.
- Enter a name for the app (e.g., "Gmail CLI").
- Click "Generate".
- Use the generated 16-character password in your
.env
file instead of your regular Gmail password.
Note: Keep this password secret and secure!
For more information or support, please open an issue on the GitHub repository.
- Manage multiple Gmail accounts from the command line
- Read, send, and forward emails
- View new and older emails
- Colorful and user-friendly interface
- Secure handling of account credentials
- Python 3.7 or higher
- pip (Python package installer)
A. gmail_multi_usr_bin.py <-- This file will be sent to the /usr/local/bin/ folder so you can run gmail from the command line.>
B. gmail_ping_test.py <-- This file must be in the same folder as gmail_multi.py and .env file to work.>
This script will test the connections after you get your app password. # Change your name from Bob below in the script. Not below, but below on Line 39 and 40 in gmail_ping_test.py.
# Get credentials from environment variables (BEST PRACTICE)
# EMAIL_USER = os.getenv("EMAIL_USER_Bob")
# EMAIL_PASS = os.getenv("EMAIL_PASS_Bob")
C. usr-bin.sh <-- This script is to used for sending the gmail_multi_usr_bin.py to the /usr/local/bin/ folder so you can run gmail from the command line.>
D. how_to_use.md <-- This File will help you setup gmail_multi_usr_bin.py to be able to run on the command line.>
Note. Both gmail scripts need google user and password, the only difference is that the Bin version has the users and passwords inside the scripts while the gmail_multi.py saves the user names and passwords to a .env file for security.
The bin version is also secure, as you will need to use your password to save the files into the location, I did on my Macbook Pro m3. And anytime I change anything I have to enter my password.
-
Clone the repository:
git clone https://github.com/yourusername/gmail-multi-cli.git cd gmail-multi-cli
-
Create a virtual environment (optional but recommended):
NOTE: I don't myself, but if you don't know what a virtual environment (venv) is then not need to do this.
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Set up your
.env
file with your Gmail account credentials (see Configuration section). -
Install the modules needed to run the script Requirements.txt
Locate a file named
requirements.txt
in your project directory with the following content:python-dotenv==0.19.2 colorama==0.4.4
Install requirements.txt
pip install requirements.txt
-
Run the script:
python gmail_multi.py
-
Congrats!
An app password is a 16-digit passcode that gives a less secure app or device permission to access your Google Account. App passwords can only be used with accounts that have 2-Step Verification turned on.
Create and manage your app passwords. You may need to sign in to your Google Account.
If you’ve set up 2-Step Verification but can’t find the option to add an app password, it might be because:
- Your Google Account has 2-Step Verification set up only for security keys.
- You’re logged into a work, school, or another organization account.
- Your Google Account has Advanced Protection.
Tip: Usually, you’ll need to enter an app password once per app or device.
- To create an app password, you need 2-Step Verification on your Google Account.
- Go to your Google Account's App Passwords page: https://myaccount.google.com/apppasswords
- Select "Mail" and "Other (Custom name)" from the dropdowns.
- Enter a name for the app (e.g., "Gmail CLI").
- Click "Generate".
- Use the generated 16-character password in your
.env
file instead of your regular Gmail password.
Note: Keep this password secret and secure!
After installation and setup, run the script:
python gmail_multi.py
Follow the on-screen prompts to:
- Select an account
- Choose an action (read new emails, check older emails, send an email, etc.)
- Perform email operations
Create a .env
file in the project root with your Gmail account credentials:
The app password is 16 letter in length with spaces between every 4 letters, example fejylpueanyepjeb
So to add the password like this EMAIL_PASS_TheDude=fejylpueanyepjeb and this format works.
You will need to change you details in
-
The .env file see below for the format. (See a few lines below)
-
You will need to also change your names in the gmail_multi.py @ Line 87 'def select_account():' (See a few lines below)
-
The .env file
[email protected] EMAIL_PASS_TheDude=app_password [email protected] EMAIL_PASS_Man=app_password [email protected] EMAIL_PASS_SpaceMan=app_password
-
gmail_multi.py
def select_account(): print_ascii_gmail2() print(Fore.YELLOW + "\nSelect an account:") print("1. Bob") print("2. Man") print("3. Linky") print("0. Exit" + Style.RESET_ALL)
Replace the email addresses and passwords with your actual Gmail credentials.
- Authentication Error: Ensure you've enabled "Less Secure App Access" or are using an App Password.
- Module Not Found Error: Make sure you've installed all required packages (
pip install -r requirements.txt
). - SMTP Connection Error: Check your internet connection and firewall settings.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- CLI: Command Line Interface - a text-based interface for interacting with a program.
- IMAP: Internet Message Access Protocol - used for retrieving emails from a server.
- SMTP: Simple Mail Transfer Protocol - used for sending emails.
- Virtual Environment: An isolated Python environment that allows you to install packages without affecting your system-wide Python installation.
- App Password: A 16-character password that gives a less secure app or device permission to access your Google Account.
For more information or support, please open an issue on the GitHub repository.