Skip to main content
userharbor

GitHub License Tests Codecov PyPI - Python Version PyPI - Version Code style: black Linting: Ruff uv Pytest Zensical

SMTP email sender integration for userharbor.

The package provides SMTPEmailSender, an implementation of UserHarbor's EmailSender protocol. It sends verification, password reset, and account security notification messages with Python's standard smtplib and renders HTML email templates with Jinja.

Installation

pip install userharbor-smtp

Usage

from userharbor_smtp import SMTPEmailSender

email_sender = SMTPEmailSender(
    host="smtp.example.com",
    port=587,
    username="smtp-user",
    password="smtp-password",
    from_email="noreply@example.com",
    from_name="UserHarbor",
)

By default, the sender uses HTML templates bundled with the package:

  • verification.html
  • password_reset.html
  • email_verified.html
  • password_changed.html
  • account_deleted.html

To use custom templates, pass a pathlib.Path to a directory containing files with the same names:

from pathlib import Path

email_sender = SMTPEmailSender(
    host="smtp.example.com",
    port=587,
    username="smtp-user",
    password="smtp-password",
    from_email="noreply@example.com",
    template_dir=Path("templates/emails"),
    template_context={"app_url": "https://example.com"},
)

Each template receives:

  • username
  • email
  • token for verification and password reset messages

Use template_context to add variables to every template. Built-in variables username, email, and token take precedence over custom values.

Example templates/emails/verification.html:

<p>Hello {{ username }},</p>
<p><a href="{{ app_url }}/auth/verify_email?token={{ token | urlencode }}">Verify {{ email }}</a></p>

Configuration

SMTPEmailSender(
    host="smtp.example.com",
    from_email="noreply@example.com",
    port=587,
    username=None,
    password=None,
    from_name=None,
    template_dir=None,
    template_context=None,
    verification_subject="Verify your email",
    password_reset_subject="Reset your password",
    email_verified_subject="Email verified",
    password_changed_subject="Password changed",
    account_deleted_subject="Account deleted",
    use_starttls=True,
    use_ssl=False,
    ssl_context=None,
    allow_insecure=False,
    timeout=10,
)

TLS certificate and hostname verification use Python's secure default SSL context. Pass ssl_context only when the application needs a custom trusted certificate authority or TLS policy. At least one of use_starttls and use_ssl must be enabled by default. Set allow_insecure=True only for a trusted local SMTP relay where plaintext transport is an explicit decision.

License

UserHarbor SMTP is released under the MIT License.

Metadata

Release files for userharbor-smtp 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for userharbor-smtp 0.4.0
File Size Uploaded Provenance Actions
userharbor_smtp-0.4.0.tar.gz 4.8 kB Without provenance Details for userharbor_smtp-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for userharbor-smtp 0.4.0
File Interpreter ABI Platform Actions
userharbor_smtp-0.4.0-py3-none-any.whl Python 3 none any Details for userharbor_smtp-0.4.0-py3-none-any.whl

Total release size: 11.3 kB

Release files / userharbor_smtp-0.4.0.tar.gz

Download URL userharbor_smtp-0.4.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3b53a7e6873768891dc2b63a1abbb2053b7963746553470d43fa97a8b3823216
BLAKE2b-256 checksum
How to use checksums
551b003fd943de44fd58e9f7471f96299704184636036ab2d6bbca0940e078c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / userharbor_smtp-0.4.0-py3-none-any.whl

Download URL userharbor_smtp-0.4.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59d4a5cd808fc1761c599159db2c6d926556a3131f96fb11731dc9b3c2176040
BLAKE2b-256 checksum
How to use checksums
3da808fe8d8dcedc83646a6150eedacbae089a636eda6b4efc517dfbe298f5dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for userharbor-smtp 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page