Files
fn_registry/python/functions/infra/email_build_html.md
T
egutierrez be081c68f2 feat: funciones email SMTP en Python (infra)
smtp_send: conecta+envia+cierra en un paso via smtplib (TLS/STARTTLS/plain).
email_build_html: construye EmailMessagePy frozen dataclass con cuerpo HTML.
Solo stdlib Python: smtplib, email.mime. Tests con mock SMTP server threading.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 02:03:12 +02:00

1.8 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
email_build_html function py infra 1.0.0 pure email_build_html(from_addr: str, to: list[str], subject: str, body_html: str) -> EmailMessagePy Construye un EmailMessagePy inmutable con cuerpo HTML. El campo body_text queda vacio. Funcion pura sin efectos secundarios.
email
html
builder
pure
python
dataclass
false
dataclasses
name desc
from_addr direccion del remitente (ej: 'alice@example.com')
name desc
to lista de direcciones de destinatarios principales
name desc
subject asunto del correo
name desc
body_html contenido HTML del cuerpo del mensaje
EmailMessagePy inmutable con from_addr, to (como tupla), subject y body_html; body_text vacio true
construye mensaje html con campos correctos
convierte lista to a tupla inmutable
body_text queda vacio
python/functions/infra/email_build_html_test.py python/functions/infra/email_build_html.py

Ejemplo

from infra.email_build_html import email_build_html

msg = email_build_html(
    from_addr="alice@example.com",
    to=["bob@example.com", "carol@example.com"],
    subject="Reporte mensual",
    body_html="<h1>Hola</h1><p>Ver adjunto.</p>",
)
assert msg.body_html == "<h1>Hola</h1><p>Ver adjunto.</p>"
assert msg.body_text == ""
assert isinstance(msg.to, tuple)

Notas

Funcion pura. EmailMessagePy es un dataclass frozen — inmutable por construccion. La lista to se convierte a tupla para evitar mutacion externa. Para usar con smtp_send, pasar los campos del mensaje como argumentos individuales.