Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Mail Ship: A powerful Python library for email automation and testing. It offers Gmail integration, real-time inbox monitoring, content extraction, and seamless Selenium integration. Perfect for developers navigating complex email-based workflows and testing scenarios.
MailShip is a Python library designed to simplify Gmail-related automation tasks, particularly useful for testing and automation scenarios involving email interactions.
Install MailShip using pip:
pip install mail-ship
then Run the setup script:
mail-ship-setup
Before using MailShip, you need to set up a Google Cloud project and obtain OAuth credentials. Follow these steps:
client_secrets.json
in your project directory.After obtaining your credentials, run the setup script:
python setup_auth.py
This script will guide you through the process of authenticating and storing your credentials securely.
Here's a basic example of how to use MailShip:
from mailship import GmailAutomator
def run_example():
# Set verbose=True for detailed logging, False for silent operation
automator = GmailAutomator(verbose=True)
try:
email = automator.generate_email()
print(f"Generated email: {email}")
print("Waiting for an email (timeout: 60 seconds)...")
received_email = automator.wait_for_email(email, timeout=60)
if received_email:
print(f"Received email: {received_email['subject']}")
token = automator.extract_token(received_email)
link = automator.extract_link(received_email)
print(f"Extracted token: {token}")
print(f"Extracted link: {link}")
# Perform a regex search
pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
emails = automator.search_by_regex(received_email['decoded_content']['text'], pattern)
print(f"Found emails: {emails}")
else:
print("No email received within the timeout period.")
finally:
automator.cleanup()
if __name__ == "__main__":
run_example()
generate_email()
:
wait_for_email(recipient, sender=None, subject=None, timeout=180)
:
sender_domain
: Specify a domain to filter incoming emails by sender's domain.extract_token(email_content, pattern=None, token_length=None)
:
token_length
: Specify the expected length of the token to extract.extract_link(email_content, domain=None)
:
domain
: Specify a domain to filter extracted links.search_by_regex(email_content, pattern)
:
pattern
: Custom regex pattern for searching email content.These parameters allow for more precise control over email processing, making it easier to handle various testing and automation scenarios.
MailShip can be easily integrated with Selenium for end-to-end testing scenarios. Check main.py
for an example of how to use MailShip with Selenium WebDriver.
For CI/CD pipelines, use the main_ci.py
script, which is designed to work with GitHub Actions. To set up GitHub Actions for your project:
Create a .github/workflows/gmail_automation.yml
file in your repository
Use the template provided in the ci.yml
file in this repository, adjusting as needed. This template includes setup for Selenium with Chrome in a headless environment.
Set up the required secrets in your GitHub repository settings:
Contributions to MailShip are welcome! Here's how you can contribute:
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository. Provide as much detail as possible, including:
This project is licensed under a Custom Repository License - see the LICENSE file for details. This license allows free use, modification, and distribution within this repository, but restricts external use without permission.
@OluwaseyiAjadi4 - Twitter Oluwaseyi Ajadi - Linkedin
FAQs
Mail Ship: A powerful Python library for email automation and testing. It offers Gmail integration, real-time inbox monitoring, content extraction, and seamless Selenium integration. Perfect for developers navigating complex email-based workflows and testing scenarios.
We found that mailship demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.