A simple Python mailer for SMTP sending.
Project description
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
-
Clone or download this repository.
-
Navigate to the project directory (where
pyproject.tomlorsetup.pyis located). -
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
25or587(ifuse_tls=True), or465(ifuse_ssl=True). - use_tls (bool): Set to
Trueto enable STARTTLS after connecting. Typically used with port 587. - use_ssl (bool): Set to
Trueif you want an SSL connection from the start (SMTPS). Typically used with port 465. - use_auth (bool): Set to
Trueif 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mymailsender-0.1.6.tar.gz.
File metadata
- Download URL: mymailsender-0.1.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70af6358405f6bdb14988249ce5c4d471376e424741fe6eaae48ea8bf9da4b58
|
|
| MD5 |
22f07863cea4d9e82ec04ad270ebc243
|
|
| BLAKE2b-256 |
ddf59ce199c336add9b22b60cd7d2f8ab9ec3a7eda8fc61f8cf51fa20d6ac1c3
|
Provenance
The following attestation bundles were made for mymailsender-0.1.6.tar.gz:
Publisher:
python-publish.yml on mariusei/mymailsender
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mymailsender-0.1.6.tar.gz -
Subject digest:
70af6358405f6bdb14988249ce5c4d471376e424741fe6eaae48ea8bf9da4b58 - Sigstore transparency entry: 157898637
- Sigstore integration time:
-
Permalink:
mariusei/mymailsender@66ccfce06980c39bb17786e66f7494c615bda51a -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/mariusei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@66ccfce06980c39bb17786e66f7494c615bda51a -
Trigger Event:
release
-
Statement type:
File details
Details for the file mymailsender-0.1.6-py3-none-any.whl.
File metadata
- Download URL: mymailsender-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d863d832ca1b6119f007fe339460f4aaaa46ee779e86f138db4ae821a7d69d9
|
|
| MD5 |
dd80932b2051215a85773c8001f55407
|
|
| BLAKE2b-256 |
a9403e9c97c40dafd95e87159a9411c80ac5507e4aeaf44eae294d6720d4389b
|
Provenance
The following attestation bundles were made for mymailsender-0.1.6-py3-none-any.whl:
Publisher:
python-publish.yml on mariusei/mymailsender
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mymailsender-0.1.6-py3-none-any.whl -
Subject digest:
9d863d832ca1b6119f007fe339460f4aaaa46ee779e86f138db4ae821a7d69d9 - Sigstore transparency entry: 157898638
- Sigstore integration time:
-
Permalink:
mariusei/mymailsender@66ccfce06980c39bb17786e66f7494c615bda51a -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/mariusei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@66ccfce06980c39bb17786e66f7494c615bda51a -
Trigger Event:
release
-
Statement type: