{"id":14904,"library":"secure-smtplib","title":"secure-smtplib (Python 2)","description":"secure-smtplib is an abandoned Python 2 library (last released in 2015) that provides subclasses for the standard `smtplib` module to handle secure SMTP connections. Its functionality has been largely superseded by built-in improvements to the standard `smtplib` module in Python 3, which offers robust SSL/TLS support through `SMTP_SSL` and `starttls()` methods, often in conjunction with the `ssl` module. This library is not recommended for new projects or Python 3 environments due to its age and lack of maintenance.","status":"abandoned","version":"0.1.1","language":"en","source_language":"en","source_url":"https://github.com/graingert/secure-smtplib","tags":["email","smtp","ssl","tls","python2","abandoned"],"install":[{"cmd":"pip install secure-smtplib","lang":"bash","label":"Install secure-smtplib"}],"dependencies":[],"imports":[{"symbol":"SecureSMTP","correct":"from secure_smtplib import SecureSMTP"},{"symbol":"SecureSMTP_SSL","correct":"from secure_smtplib import SecureSMTP_SSL"}],"quickstart":{"code":"import smtplib\nimport ssl\nimport os\nfrom email.message import EmailMessage\n\n# NOTE: This quickstart uses Python 3's built-in smtplib and ssl modules,\n# which are the recommended and secure way to send emails. The `secure-smtplib`\n# library itself is deprecated and not suitable for modern Python or secure applications.\n\nSMTP_SERVER = os.environ.get('SMTP_HOST', 'smtp.example.com')\nSMTP_PORT = int(os.environ.get('SMTP_PORT', '465')) # Use 587 for STARTTLS\nEMAIL_ADDRESS = os.environ.get('SMTP_USERNAME', 'your_email@example.com')\nEMAIL_PASSWORD = os.environ.get('SMTP_PASSWORD', 'your_app_password') # Use app passwords if 2FA is enabled\n\nmsg = EmailMessage()\nmsg['Subject'] = 'Test Email from Python'\nmsg['From'] = EMAIL_ADDRESS\nmsg['To'] = 'recipient@example.com'\nmsg.set_content('This is a test email sent securely using Python 3 smtplib.')\n\ncontext = ssl.create_default_context()\n\ntry:\n    with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT, context=context) as server:\n        server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)\n        server.send_message(msg)\n    print(\"Email sent successfully!\")\nexcept smtplib.SMTPAuthenticationError as e:\n    print(f\"Authentication error: {e}. Check your username and password/app password.\")\nexcept smtplib.SMTPServerDisconnected as e:\n    print(f\"Server disconnected unexpectedly: {e}. Check host and port.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Migrate to Python 3 and use the built-in `smtplib` and `ssl` modules for secure email functionality.","message":"This 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.","severity":"breaking","affected_versions":"0.1.1 and earlier"},{"fix":"Discontinue use of `secure-smtplib` and leverage the `smtplib` and `ssl` modules available in Python 3.","message":"The 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.","severity":"deprecated","affected_versions":"0.1.1 and earlier"},{"fix":"Avoid 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.","message":"The 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.","severity":"gotcha","affected_versions":"0.1.1 and earlier"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[],"ecosystem":"pypi"}