Skip to main content

Auto-rotating secret generation with Argon2 hashing and scheduled SMTP delivery

Project description

scheduled-email

Auto-rotating secret generation — creates Argon2-hashed secrets and delivers password-less login links via SMTP on a configurable schedule.

Install

pip install scheduled-email

尚未发布到 PyPI 前,需先按 PUBLISH.md 完成上传。 本地开发可用 editable 模式:pip install -e packages/scheduled-email

Environment Variables

Variable Required Default Description
SCHEDMAIL_SMTP_USER yes Sender email address
SCHEDMAIL_SMTP_PASS yes SMTP authorization code
SCHEDMAIL_RECIPIENT yes Recipient email address
SCHEDMAIL_BASE_URL no https://example.com/login?token= Prefix for login URL
SCHEDMAIL_ROTATE_HOURS no 24 Rotation interval (hours)
SCHEDMAIL_SCT no *****-daiju SCT constant
SCHEDMAIL_MASK_SECRET no false Mask secret in email body

Copy .env.example to .env and fill in credentials. Never commit .env.

Usage

Standalone

from scheduled_email import start, stop

svc = start()       # immediate first rotation + email, then every 24h
# ...
stop()               # cancel timer

Context Manager

from scheduled_email import ScheduledEmailService

with ScheduledEmailService() as svc:
    print(svc.current_url)

FastAPI Integration (minimal)

from contextlib import asynccontextmanager
from fastapi import FastAPI

@asynccontextmanager
async def lifespan(app: FastAPI):
    from scheduled_email import start, stop
    start()
    yield
    stop()

app = FastAPI(lifespan=lifespan)

How It Works

  1. On start(), a 32-byte random secret is generated via secrets.token_urlsafe.
  2. The secret is hashed with Argon2 (argon2-cffi).
  3. A login URL is built: {SCHEDMAIL_BASE_URL}{argon2_hash}.
  4. An email is sent via SMTP_SSL containing: rotation time, SCT, secret (optionally masked), and the full login URL.
  5. A threading.Timer schedules the next rotation after SCHEDMAIL_ROTATE_HOURS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scheduled_email-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scheduled_email-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file scheduled_email-0.1.0.tar.gz.

File metadata

  • Download URL: scheduled_email-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for scheduled_email-0.1.0.tar.gz
Algorithm Hash digest
SHA256 172ec0506334782b56725b1202467ec6972a326172c596045cec3ceec5737b6f
MD5 b050041c9d5bbd092571eed14174a82e
BLAKE2b-256 75518de11de06683f077b7efe155c20526041d5a4a409f1901e416fe6d795164

See more details on using hashes here.

File details

Details for the file scheduled_email-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for scheduled_email-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c2bfcfe1c4c699a57781683251ff5b3746bcde3acfc910c6bac99ec87f5321e
MD5 7aba8c1a888cea46cc42e3028e597e41
BLAKE2b-256 fe2abacaf2e51f39e17ea11317b2e6f1eb1abd1947631f97608b8d19b915d99f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page