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",
    templateId="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'],
    replyTo="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.
  • templateId (str, optional): Template ID for the email.
  • replyTo (str, optional): Reply-to email address.
  • inReplyTo (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.0.tar.gz (6.3 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.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mailtransport-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 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.0.tar.gz
Algorithm Hash digest
SHA256 654af7aa909541da54c52b8bce95abdede7740a458ad76d7f784d37295850c04
MD5 3bd29bba19d221d9d8ad26c9c03bd3a0
BLAKE2b-256 150d625087f469acf9a8bb36bd210fe8ca5d007224d418acb72473fb998bd680

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mailtransport-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f45f8120b1d8646e48a888fa573a0d56ff8c34c9400ed4f76794a34b4be6191
MD5 a4fa926386f47960a4dd209b712f6f11
BLAKE2b-256 46c3d628533f49c0ed0e13ed18e6928717dc623a1d5ab1fa0d34e7daea8111e5

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