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>
25 lines
758 B
Go
25 lines
758 B
Go
package infra
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"text/template"
|
|
)
|
|
|
|
// EmailTemplateRender executes a Go text/template with the given data map
|
|
// and returns the rendered string.
|
|
// tmplStr is the template source (Go text/template syntax).
|
|
// data is a map of string keys to any values available inside the template.
|
|
// Returns an error if the template fails to parse or execute.
|
|
func EmailTemplateRender(tmplStr string, data map[string]any) (string, error) {
|
|
tmpl, err := template.New("email").Parse(tmplStr)
|
|
if err != nil {
|
|
return "", fmt.Errorf("email_template_render: parse: %w", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
if err := tmpl.Execute(&buf, data); err != nil {
|
|
return "", fmt.Errorf("email_template_render: execute: %w", err)
|
|
}
|
|
return buf.String(), nil
|
|
}
|