feat: tipos y funciones email SMTP en Go (infra)
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>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package infra
|
||||
|
||||
// EmailWithAttachment returns a copy of msg with the given attachment appended.
|
||||
// Does not mutate the original message — always returns a new EmailMessage.
|
||||
func EmailWithAttachment(msg EmailMessage, att EmailAttachment) EmailMessage {
|
||||
newAtts := make([]EmailAttachment, len(msg.Attachments)+1)
|
||||
copy(newAtts, msg.Attachments)
|
||||
newAtts[len(msg.Attachments)] = att
|
||||
|
||||
toSlice := make([]string, len(msg.To))
|
||||
copy(toSlice, msg.To)
|
||||
|
||||
ccSlice := make([]string, len(msg.CC))
|
||||
copy(ccSlice, msg.CC)
|
||||
|
||||
bccSlice := make([]string, len(msg.BCC))
|
||||
copy(bccSlice, msg.BCC)
|
||||
|
||||
var headers map[string]string
|
||||
if len(msg.Headers) > 0 {
|
||||
headers = make(map[string]string, len(msg.Headers))
|
||||
for k, v := range msg.Headers {
|
||||
headers[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return EmailMessage{
|
||||
From: msg.From,
|
||||
To: toSlice,
|
||||
CC: ccSlice,
|
||||
BCC: bccSlice,
|
||||
Subject: msg.Subject,
|
||||
BodyHTML: msg.BodyHTML,
|
||||
BodyText: msg.BodyText,
|
||||
Attachments: newAtts,
|
||||
Headers: headers,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user