Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-03-23 09:58:44 +03:00
parent 5eab36df69
commit c0053d6058
7 changed files with 345 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ package mailer
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
@@ -145,6 +146,36 @@ func (g *GraphMailer) Send(ctx context.Context, msg Message) error {
message["replyTo"] = replyToRecipients
}
if len(msg.Attachments) > 0 {
atts := make([]map[string]any, 0, len(msg.Attachments))
for _, a := range msg.Attachments {
if len(a.Data) == 0 {
continue
}
name := strings.TrimSpace(a.FileName)
if name == "" {
name = "attachment.bin"
}
contentType := strings.TrimSpace(a.ContentType)
if contentType == "" {
contentType = "application/octet-stream"
}
atts = append(atts, map[string]any{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": name,
"contentType": contentType,
"contentBytes": base64.StdEncoding.EncodeToString(a.Data),
})
}
if len(atts) > 0 {
message["attachments"] = atts
}
}
payload := map[string]any{
"message": message,
"saveToSentItems": true,