Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -18,10 +18,17 @@ type Mailer struct {
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
To []string
|
||||
Subject string
|
||||
Body string
|
||||
BodyHTML string
|
||||
To []string
|
||||
Subject string
|
||||
Body string
|
||||
BodyHTML string
|
||||
Attachments []Attachment
|
||||
}
|
||||
|
||||
type Attachment struct {
|
||||
FileName string
|
||||
ContentType string
|
||||
Data []byte
|
||||
}
|
||||
|
||||
func New(cfg Config) *Mailer {
|
||||
|
||||
Reference in New Issue
Block a user