Here’s a more concise and focused README.md tailored specifically for the PyPI package, including a link to the GitHub repository for detailed documentation.
MailShip
MailShip is a Python library designed to simplify Gmail automation for developers and testers. It offers tools for email generation, email content extraction, and seamless integration with CI/CD pipelines and testing frameworks.
Features
- Generate unique email addresses for testing.
- Wait for and retrieve emails in real time.
- Extract tokens and links from email content.
- Perform regex-based searches on email content.
- Automatically refresh Gmail API tokens via cron jobs or pipelines.
- CI/CD ready with GitHub Actions integration.
Installation
Install the library using pip:
pip install mailship
Configuration
Before using MailShip, you need to set up a Google Cloud project and configure OAuth credentials. Follow the steps below:
Step 1: Create a Google Cloud Project
- Visit the Google Cloud Console.
- Click on the project selector at the top and choose "New Project."
- Enter a name for your project (e.g., "MailShip") and click "Create."
- Select your new project from the project dropdown once it's created.
Step 2: Enable the Gmail API
- Go to "APIs & Services" > "Library" in the left sidebar.
- Search for "Gmail API" and select it.
- Click "Enable" to activate the API for your project.
Step 3: Configure the OAuth Consent Screen
- Navigate to "APIs & Services" > "OAuth consent screen."
- Select "External" (or "Internal" for Google Workspace accounts).
- Fill in the following fields:
- App Name: MailShip
- User Support Email: Your email address
- Developer Contact Information: Your email address
- Add these required scopes on the "Scopes" page:
- Save the settings and add your Gmail account under "Test Users."
Step 4: Create an OAuth 2.0 Client ID
- Go to "APIs & Services" > "Credentials."
- Click "Create Credentials" > "OAuth client ID."
- Choose "Desktop app" as the application type.
- Name the client (e.g., "MailShip Desktop Client") and click "Create."
- Download the
client_secrets.jsonfile and place it in your project directory.
Getting Started
After getting your credentials, you can initialize the setup process:
Run one of the following commands to set up your Gmail API credentials:
Option 1: Setup Gmail Authentication
Run the following command to set up your Gmail API credentials without automatic token refreshing setup.
Note: TOkens would expire if app is not used for long periods of time
mail-ship-setup
This will guide you through the setup process, including storing credentials and setting environment variables.
Option 2: Set Up Automatic Token Refreshing (Linux)
- To set up a cron job (Linux/macOS) for automatic token refreshing, run:
mail-ship-setup --setup-cron
Option 3: Set Up Automatic Token Refreshing (Windows)
- To set up a scheduled task (Windows), run:
mail-ship-setup --setup-task
For more detailed setup instructions, visit the GitHub repository.
Basic Usage
Here’s a quick example of how to use MailShip:
from mailship import GmailAutomator
automator = GmailAutomator(verbose=True)
# Generate a unique email for testing
email = automator.generate_email()
print(f"Generated email: {email}")
# Wait for an email
received_email = automator.wait_for_email(email, timeout=120)
if received_email:
print(f"Received email: {received_email['subject']}")
# Extract a token from the email
token = automator.extract_token(received_email)
print(f"Extracted token: {token}")
else:
print("No email received within the timeout period.")
CI/CD Integration
MailShip is designed to work seamlessly in CI/CD pipelines. Add the following step in your GitHub Actions workflow to refresh Gmail API tokens:
- name: Refresh Tokens
env:
GMAIL_CLIENT_ID: ${{ secrets.GMAIL_CLIENT_ID }}
GMAIL_CLIENT_SECRET: ${{ secrets.GMAIL_CLIENT_SECRET }}
GMAIL_AUTH_REFRESH_TOKEN: ${{ secrets.GMAIL_AUTH_REFRESH_TOKEN }}
GMAIL_AUTH_SALT: ${{ secrets.GMAIL_AUTH_SALT }}
run: python -m mailship.setup_auth --refresh-tokens
Documentation
For detailed documentation, advanced features, and contributing guidelines, visit the GitHub repository.
License
This project is licensed under a Custom Repository License. See the GitHub repository for details.
Contact
For questions or support, reach out on:
- Twitter: @OluwaseyiAjadi4
- LinkedIn: Oluwaseyi Ajadi
This README.md is concise, focused on installation and usage, and directs users to the GitHub repository for in-depth information. Let me know if you’d like further refinements!
Metadata
Release files for mailship 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mailship-1.0.3.tar.gz | 20.7 kB | Without provenance | Details for mailship-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mailship-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for mailship-1.0.3-py3-none-any.whl |
Total release size: 39.8 kB
Release files / mailship-1.0.3.tar.gz
| Download URL | mailship-1.0.3.tar.gz |
|---|---|
| Size | 20.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36d114b230e9661c3cf260a394966401660f2aff2601fefe906b7bbdc8f7eb75
|
|
BLAKE2b-256 checksum How to use checksums |
2a479c68358810669183626c82034168f99ed322218fd9cd7d3da1cb8a73c606
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.5
|
Release files / mailship-1.0.3-py3-none-any.whl
| Download URL | mailship-1.0.3-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93a03b96f74b5d17970adcb4549531f30d1ff35ffa5c5b9082854211adc3fdc3
|
|
BLAKE2b-256 checksum How to use checksums |
f23997fd6c481d15a48dffb8fdb957ff48e76a8f2bce2661d911b9b935a3c787
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.5
|
Security for mailship 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.