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>
39 lines
1011 B
Go
39 lines
1011 B
Go
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,
|
|
}
|
|
}
|