Skip to main content

A Python package for managing email transport.

Project description

MailTransport

MailTransport is a Python package designed to simplify email transport and management. It provides an easy-to-use interface for sending emails with support for advanced configurations, attachments, and error handling.

Features

  • Send emails with HTML content, plain text, or both.
  • Add CC, BCC, and reply-to addresses.
  • Attach files with automatic MIME type detection.
  • Use templates with dynamic variables.
  • Validate email addresses and handle errors gracefully.
  • Easy integration with Python applications.

Installation

Install the package using pip:

pip install mailtransport

Quick Start

Here’s how you can get started with MailTransport:

Import and Initialize

from mailtransport import MailTransportClient

# Initialize the client with your API key
transport = MailTransportClient(api_key="your_api_key")

Send Email

Send a Simple Email

from mailtransport import MailTransportClient

# Initialize the client with your API key
transport = MailTransportClient(api_key="your_api_key")

email_instance = transport.Mail(
    to_emails=['recipient@example.com'],
    from_email="noreply@company.com",
    html="<b>This is a test email</b>",
    subject="Test Email",
)
email_instance.send()

NB: For advanced usage with all the parameters, navigate to Mailtransport docs to see full documentations

Advanced Usage

Sending Emails with Attachments

You can attach files to your email using the attach_file or add_attachment methods:

email_instance = transport.Mail(
    to_emails=['recipient@example.com'],
    from_email="noreply@company.com",
    subject="Email with Attachment",
    html="<b>Please find the attachment below.</b>"
)

# Attach a file from the filesystem
email_instance.attach_file("path/to/file.pdf")

# Attach a file with custom content and MIME type
email_instance.add_attachment(
    filename="example.txt",
    content="This is the content of the file.",
    mimetype="text/plain"
)

email_instance.send()

Using Templates with Variables

You can use templates and pass dynamic variables for personalized emails:

email_instance = transport.Mail(
    to_emails=['recipient@example.com'],
    from_email="noreply@company.com",
    template_id="template_12345",
    variables={"name": "John Doe", "order_id": "123456"}
)

email_instance.send()

Adding CC, BCC, and Reply-To Addresses

email_instance = transport.Mail(
    to_emails=['recipient@example.com'],
    from_email="noreply@company.com",
    subject="Email with CC and BCC",
    html="<b>This email has CC and BCC recipients.</b>",
    cc=['cc@example.com'],
    bcc=['bcc@example.com'],
    reply_to="replyto@example.com"
)

email_instance.send()

Error Handling

MailTransport provides detailed error messages for failed email deliveries. Use try-except blocks to handle errors gracefully:

from mailtransport.exceptions import MailTransportValidationError, MailTransportAPIError

try:
    email_instance.send()
except MailTransportValidationError as e:
    print(f"Failed to send email due to incoreect input details: {e}")
except MailTransportAPIErroras e:
    print(f"Failed to send email due to api errors: {e}")

Methods Overview

MailClient.Mail()

Creates a new email instance with the following parameters:

  • to_emails (list or str): List of recipient email addresses.
  • from_email (str): Sender's email address.
  • subject (str): Subject of the email.
  • html (str): HTML content of the email.
  • text (str, optional): Plain text content of the email.
  • cc (list, optional): List of CC email addresses.
  • bcc (list, optional): List of BCC email addresses.
  • variables (dict, optional): Variables for email templates.
  • template_id (str, optional): Template ID for the email.
  • reply_to (str, optional): Reply-to email address.
  • in_reply_to (str, optional): Message ID this email is replying to.

MailClient.attach_file(path, mimetype=None)

Attaches a file from the filesystem. The MIME type is automatically detected if not provided.

MailClient.add_attachment(filename, content, mimetype=None)

Attaches a file with custom content and MIME type.

MailClient.send(fail_silently=False)

Sends the email. If fail_silently is False, raises an exception on failure.

MailClient.is_valid_email(email)

Validates a single email address.

MailClient.is_valid_email_list(email_list, type)

Validates a list of email addresses.

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request with a detailed description of your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

For support or inquiries, please contact us at support@mailtransportai.com.

Documentation

For full documentation, visit the MailTransport Documentation.


Happy emailing with MailTransport!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailtransport-0.1.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailtransport-0.1.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file mailtransport-0.1.2.tar.gz.

File metadata

  • Download URL: mailtransport-0.1.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for mailtransport-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5e282f5e25ac2cd8fe85db08ff4ee3090781c58afb7f75e26b131a45cc7a55fe
MD5 6b49a8a94e9124f3600f2031d115a2ae
BLAKE2b-256 30f1c3e555289d5017c92ac25ccd7af780f58233dafbdf4ab2aeb51f6eb09bc4

See more details on using hashes here.

File details

Details for the file mailtransport-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mailtransport-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for mailtransport-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 67a8ff804cf5e8579ad49633d89a9659b91f088ce7201f3007078af0900fc2c5
MD5 b2b83020c6c45b5d456eebc4c8083a6b
BLAKE2b-256 041bff840707cbde510fcca3ac09eb6c4fd96974373a7ed3fff9a421dcbc93a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page