python-simple-email-sender
Project description
Python Simple Email Sender
A lightweight Python library for sending emails with attachments via SMTP.
Features
- Send emails using SMTP protocol
- Support for SSL encryption
- Add attachments to emails
- Environment variable-based configuration
- Simple logging integration
Installation
pip install python-simple-email-sender
Usage
Basic Setup
First, set up your email credentials as environment variables:
export EMAIL_ADDRESS="your.email@gmail.com"
export EMAIL_PASSWORD="your-app-password-or-email-password"
Note: For Gmail accounts, you may need to use an App Password instead of your regular password, especially if you have 2-factor authentication enabled. https://myaccount.google.com/apppasswords
Simple Example
from python_simple_email_sender import EmailSender
# Create an instance with default settings (Gmail SMTP)
sender = EmailSender()
# Send a simple email
sender.send_email(
to_email=["recipient@example.com"],
subject="Hello from Python",
message="This is a test email sent using Python Simple Email Sender."
)
Custom SMTP Server
# For a different email provider
sender = EmailSender(
server_name="smtp.yourprovider.com",
server_port=587 # Use the appropriate port for your provider
)
Sending with Attachments
sender.send_email(
to_email=["recipient@example.com", "another@example.com"],
subject="Report Attached",
message="Please find the attached report.",
attachment_file="path/to/your/file.pdf"
)
Adding Multiple Attachments
sender = EmailSender()
# Create the email
sender.msg = MIMEMultipart()
sender.msg['From'] = sender.email_address
sender.msg['To'] = 'recipient@example.com'
sender.msg['Subject'] = 'Multiple Attachments'
# Add message body
text = MIMEText("Here are the files you requested.")
sender.msg.attach(text)
# Add multiple attachments
sender.add_attachment("document.pdf", subtype="pdf")
sender.add_attachment("data.csv", subtype="csv")
sender.add_attachment("image.png", subtype="png")
# Send the email
with smtplib.SMTP_SSL(sender.server_name, sender.server_port) as smtp_server:
smtp_server.login(sender.email_address, sender.email_password)
smtp_server.sendmail(
from_addr=sender.email_address,
to_addrs=['recipient@example.com'],
msg=sender.msg.as_string()
)
🤝 Contributing
If you have a helpful tool, pattern, or improvement to suggest:
Fork the repo
Create a new branch
Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.
🙏 Thanks
Thanks for exploring this repository!
Happy coding!
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 python_simple_email_sender-1.0.8.tar.gz.
File metadata
- Download URL: python_simple_email_sender-1.0.8.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3d85bd1d3edb33336aadb3543355e9b73658670ae2377d7563f19e0046e5f9
|
|
| MD5 |
c9e2615ef2fb5d14d299919e03c1d044
|
|
| BLAKE2b-256 |
1821117c6ecc3622e87c3315d3699c2327caf7c7abe42499dd5a9c7c9da8ab06
|
File details
Details for the file python_simple_email_sender-1.0.8-py3-none-any.whl.
File metadata
- Download URL: python_simple_email_sender-1.0.8-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c269265b1e73ce6e7abdf71804426f861deca456f2da2419517d47b1dcdc19d7
|
|
| MD5 |
2e68d96bdbb7088bde7b7bbd24c0a5bd
|
|
| BLAKE2b-256 |
a7fa96238262b7da94f7f7d3f2a0ae4ed64c3141e74404d41c8d2e4347608582
|