Skip to main content

A simple Python mailer for SMTP sending.

Project description

PyPI version Build Status

MyMailSender

A simple Python wrapper for sending SMTP emails. This package lets you configure:

  • TLS/SSL or plain connections
  • Authentication or unauthenticated connections
  • Attachments, HTML/Plain text messages, CC and BCC
  • And more...

Table of Contents


Installation

  1. Clone or download this repository.

  2. Navigate to the project directory (where pyproject.toml or setup.py is located).

  3. Install in editable/development mode:

    pip install -e .
    

    Alternatively, if you've built a wheel or tar.gz:

    pip install dist/mymailsender-0.1.0-py3-none-any.whl
    

Once installed, you can import it anywhere in your code:

from mymailsender import MyMailSender

Quick Start

from mymailsender import MyMailSender

# Example instantiation of the MyMailSender class
mymailsender = MyMailSender(
    smtp_server="smtp.example.com",
    port=25,          # or 587 for TLS, 465 for SSL, etc.
    use_tls=False,    # True if you want STARTTLS
    use_ssl=False,    # True if using SSL on port 465
    use_auth=False,   # True if the server requires username/password
)

# Send a simple email
mymailsender.send_mail(
    sender_email="me@example.com",
    recipient_emails=["you@example.org"],
    subject="Hello World",
    body_text="This is a test email using mymailsender."
)

Configuration

The MyMailSender class uses a mailsender.yaml file for default configurations. This file should be placed in the project directory and can include the following settings:

smtp_server: "smtp.example.com"
port: 25
use_tls: false
use_ssl: false
use_auth: false
username: "your_username"
password: "your_password"

You can also override these settings by providing arguments when initializing the MyMailSender instance:

from mymailsender import MyMailSender

mymailsender = MyMailSender(
    smtp_server="smtp.override.com",
    port=587,
    use_tls=True,
    # Additional overrides as needed
)

The available configuration parameters are:

  • smtp_server (str): The domain or IP of your SMTP server, e.g. "smtp.gmail.com", "localhost", etc.
  • port (int): The SMTP port. Often 25 or 587 (if use_tls=True), or 465 (if use_ssl=True).
  • use_tls (bool): Set to True to enable STARTTLS after connecting. Typically used with port 587.
  • use_ssl (bool): Set to True if you want an SSL connection from the start (SMTPS). Typically used with port 465.
  • use_auth (bool): Set to True if the server requires authentication with username and password.
  • username (str, optional): Your SMTP username (if use_auth=True).
  • password (str, optional): Your SMTP password (if use_auth=True).

Usage Examples

Send a Basic Email

from mymailsender import MyMailSender

# Create the MyMailSender
mymail = MyMailSender(
    smtp_server="localhost",
    port=25,
    use_tls=False,
    use_ssl=False,
    use_auth=False
)

# Send a basic text-only message
mymail.send_mail(
    sender_email="sender@localhost",
    recipient_emails=["recipient@localhost"],
    subject="Test Email",
    body_text="Hello from mymailsender!",
)

Send an Email with Attachments

from mymailsender import MyMailSender

mymail = MyMailSender(
    smtp_server="smtp.example.com",
    port=587,
    use_tls=True,
    use_ssl=False,
    use_auth=True,
    username="myuser",
    password="mypassword"
)

mymail.send_mail(
    sender_email="myuser@example.com",
    recipient_emails=["recipient@example.org"],
    subject="Hello with Attachments",
    body_text="Hello, please see the attached files.",
    attachments=[
        "reports/report1.pdf",
        "/path/to/image.png"
    ]
)

Using CC and BCC

Configure some custom connection settings in mailsender.yaml:

smtp_server: "smtp.example.com"
username: myusername
password: mypass

Which now allows you to initialize the MyMailSender instance without specifying any arguments:

from mymailsender import MyMailSender

mymail = MyMailSender()

mymail.send_mail(
    sender_email="me@example.com",
    recipient_emails=["primary@example.org"],
    subject="Test CC and BCC",
    body_text="Hello, just testing CC and BCC!",
    cc_emails=["colleague@example.org"],
    bcc_emails=["secret@example.org"]
)

License

This project is distributed under the MIT License. Feel free to use it, modify it, or distribute it as you wish. See LICENSE for more information.

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

mymailsender-0.1.5.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

mymailsender-0.1.5-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file mymailsender-0.1.5.tar.gz.

File metadata

  • Download URL: mymailsender-0.1.5.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mymailsender-0.1.5.tar.gz
Algorithm Hash digest
SHA256 72f402fc34ccc00da807f13ccdecb6eaa252abae904b4809e4828a13174cc914
MD5 c78215d43b4114e9e30ab17852a52acb
BLAKE2b-256 902eae8d78d0a0c9a4fbd4aa85fd4316682512d9004357675df96d9997ffcf4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mymailsender-0.1.5.tar.gz:

Publisher: python-publish.yml on mariusei/mymailsender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mymailsender-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mymailsender-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mymailsender-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c8567085ea0de0f594193ead09966ec659e0dd817802b9ed0260991f3e5d55dd
MD5 1b350006b955ec8dc6bfb3f55adbe4d1
BLAKE2b-256 4aa29d26e22de9bee51b60c7382424310abe632c2eeb50807daf9f1488dca7b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mymailsender-0.1.5-py3-none-any.whl:

Publisher: python-publish.yml on mariusei/mymailsender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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