Install & Compatibility
Where this runs
tested against v0.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SecureSMTP
✓ from secure_smtplib import SecureSMTP
SecureSMTP_SSL
✓ from secure_smtplib import SecureSMTP_SSL
This quickstart demonstrates how to send a secure email using Python 3's built-in `smtplib` and `ssl` modules. This is the **recommended modern approach** for secure email communication and should be used **instead of** the `secure-smtplib` library, which is outdated. Ensure you set `SMTP_HOST`, `SMTP_PORT`, `SMTP_USERNAME`, and `SMTP_PASSWORD` environment variables for authentication.
import smtplib
import ssl
import os
from email.message import EmailMessage
# NOTE: This quickstart uses Python 3's built-in smtplib and ssl modules,
# which are the recommended and secure way to send emails. The `secure-smtplib`
# library itself is deprecated and not suitable for modern Python or secure applications.
SMTP_SERVER = os.environ.get('SMTP_HOST', 'smtp.example.com')
SMTP_PORT = int(os.environ.get('SMTP_PORT', '465')) # Use 587 for STARTTLS
EMAIL_ADDRESS = os.environ.get('SMTP_USERNAME', 'your_email@example.com')
EMAIL_PASSWORD = os.environ.get('SMTP_PASSWORD', 'your_app_password') # Use app passwords if 2FA is enabled
msg = EmailMessage()
msg['Subject'] = 'Test Email from Python'
msg['From'] = EMAIL_ADDRESS
msg['To'] = 'recipient@example.com'
msg.set_content('This is a test email sent securely using Python 3 smtplib.')
context = ssl.create_default_context()
try:
with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT, context=context) as server:
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
server.send_message(msg)
print("Email sent successfully!")
except smtplib.SMTPAuthenticationError as e:
print(f"Authentication error: {e}. Check your username and password/app password.")
except smtplib.SMTPServerDisconnected as e:
print(f"Server disconnected unexpectedly: {e}. Check host and port.")
except Exception as e:
print(f"An error occurred: {e}")
Debug
Known issues
breakingThis library is designed for Python 2 and is not compatible with Python 3. Attempting to use it in a Python 3 environment will likely result in import errors or unexpected behavior.fixMigrate to Python 3 and use the built-in `smtplib` and `ssl` modules for secure email functionality.
affects: 0.1.1 and earlier
deprecatedThe functionality provided by `secure-smtplib` for secure SMTP connections (SSL/TLS) has been integrated into and significantly improved within Python's standard `smtplib` module since Python 3.3. The standard library now offers `smtplib.SMTP_SSL` for implicit TLS and `smtplib.SMTP().starttls()` for explicit TLS, along with `ssl.create_default_context()` for robust security configuration.fixDiscontinue use of `secure-smtplib` and leverage the `smtplib` and `ssl` modules available in Python 3.
affects: 0.1.1 and earlier
gotchaThe library is unmaintained (last updated in 2015) and specifically targets Python 2. Using unmaintained software, especially for network communication involving credentials, can introduce significant security vulnerabilities.fixAvoid using `secure-smtplib` in production or security-sensitive applications. Prioritize actively maintained libraries or the robust built-in `smtplib` module in Python 3 for secure email operations.
affects: 0.1.1 and earlier
Upgrade
Version history
0.1.1latest on PyPI · released Apr 7, 2015
Audit
Dependencies
No dependency data recorded yet.
Resources
No resource links recorded.