ef3ae2aae9
Tipos: EmailAttachment, EmailMessage, SMTPConfig. Puras: email_build_html, email_build_text, email_with_attachment, email_template_render. Impuras: smtp_connect (TLS/STARTTLS/plain), smtp_send (MIME multipart con adjuntos). Solo stdlib: net/smtp, crypto/tls, text/template, mime/multipart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.5 KiB
Markdown
44 lines
1.5 KiB
Markdown
---
|
|
name: smtp_connect
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func SMTPConnect(cfg SMTPConfig) (*smtp.Client, error)"
|
|
description: "Establece una conexion SMTP autenticada. TLSMode 'tls' usa TLS directo (port 465), 'starttls' hace upgrade STARTTLS (port 587), '' sin cifrado (port 25). Retorna un *smtp.Client listo para usar con SMTPSend."
|
|
tags: [email, smtp, connection, tls, starttls, auth]
|
|
uses_functions: []
|
|
uses_types: [SMTPConfig_go_infra]
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: ["crypto/tls", "fmt", "net", "net/smtp"]
|
|
params:
|
|
- name: cfg
|
|
desc: "configuracion SMTP: host, port, usuario, password y modo TLS"
|
|
output: "*smtp.Client autenticado y listo para enviar mensajes; el caller debe llamar client.Quit() al terminar"
|
|
tested: true
|
|
tests:
|
|
- "conecta sin cifrado a servidor mock"
|
|
- "error si el servidor no existe"
|
|
test_file_path: "functions/infra/smtp_connect_test.go"
|
|
file_path: "functions/infra/smtp_connect.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
cfg := SMTPConfig{Host: "smtp.gmail.com", Port: 587, Username: "u@gmail.com", Password: "app-pw", TLSMode: "starttls"}
|
|
client, err := SMTPConnect(cfg)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer client.Quit()
|
|
// pasar client a SMTPSend(...)
|
|
```
|
|
|
|
## Notas
|
|
|
|
Funcion impura — abre conexion TCP real. El caller es responsable de cerrar el cliente con `client.Quit()`. Para test unitario usar un listener TCP local como mock. `SMTPSend` acepta el `*smtp.Client` retornado por esta funcion.
|