
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
A modern and efficient Python library for sending emails with SMTP, Jinja2 templates, and attachments.
MailToolsBox is a modern, feature-rich Python package designed for sending and managing emails with ease. It provides robust functionality for handling SMTP email sending, template-based emails using Jinja2, attachments, CC/BCC support, and email validation. Additionally, MailToolsBox ensures backward compatibility with legacy implementations.
SendAgent
Install MailToolsBox from PyPI using pip:
pip install MailToolsBox
The EmailSender
class is the primary interface for sending emails. Below is an example of sending a simple plain text email:
from MailToolsBox import EmailSender
# Email configuration
sender = EmailSender(
user_email="your@email.com",
server_smtp_address="smtp.example.com",
user_email_password="yourpassword",
port=587
)
# Sending email
sender.send(
recipients=["recipient@example.com"],
subject="Test Email",
message_body="Hello, this is a test email!"
)
sender.send(
recipients=["recipient@example.com"],
subject="HTML Email Example",
message_body="""<h1>Welcome!</h1><p>This is an <strong>HTML email</strong>.</p>""",
html=True,
attachments=["/path/to/document.pdf"]
)
MailToolsBox allows sending emails using Jinja2 templates stored in the templates/
directory.
templates/welcome.html
):<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome, {{ username }}!</h1>
<p>Click <a href="{{ activation_link }}">here</a> to activate your account.</p>
</body>
</html>
context = {
"username": "John Doe",
"activation_link": "https://example.com/activate"
}
sender.send_template(
recipient="recipient@example.com",
subject="Welcome to Our Service",
template_name="welcome.html",
context=context
)
sender.send(
recipients=["recipient@example.com"],
subject="CC & BCC Example",
message_body="This email has CC and BCC recipients!",
cc=["cc@example.com"],
bcc=["bcc@example.com"]
)
SendAgent
For those migrating from earlier versions, SendAgent
ensures seamless compatibility:
from MailToolsBox import SendAgent
legacy_sender = SendAgent(
user_email="your@email.com",
server_smtp_address="smtp.example.com",
user_email_password="yourpassword",
port=587
)
legacy_sender.send_mail(
recipient_email=["recipient@example.com"],
subject="Legacy Compatibility Test",
message_body="Testing backward compatibility."
)
Example using environment variables:
import os
sender = EmailSender(
user_email=os.getenv("EMAIL"),
server_smtp_address=os.getenv("SMTP_SERVER"),
user_email_password=os.getenv("EMAIL_PASSWORD"),
port=int(os.getenv("SMTP_PORT", 587))
)
MailToolsBox provides built-in logging to help debug issues:
import logging
logging.basicConfig(level=logging.INFO)
Example of handling exceptions:
try:
sender.send(
recipients=["recipient@example.com"],
subject="Error Handling Test",
message_body="This is a test email."
)
except Exception as e:
print(f"Failed to send email: {e}")
MailToolsBox is an open-source project. Contributions are welcome! To contribute:
For discussions, visit rambod.net.
MailToolsBox is licensed under the MIT License. See the LICENSE for details.
FAQs
A modern and efficient Python library for sending emails with SMTP, Jinja2 templates, and attachments.
We found that MailToolsBox demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.