You've already forked email-api-client
feat: add FileAttachment type and functions for creating attachments from file content and file path
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 20s
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 20s
This commit is contained in:
33
client/attachment.go
Normal file
33
client/attachment.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func NewAttachmentFromFileContent(fileName string, f []byte) (*FileAttachment, error) {
|
||||
base64.StdEncoding.Encode(f, f)
|
||||
|
||||
return &FileAttachment{
|
||||
Filename: fileName,
|
||||
Content: string(f),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewAttachmentFromFilePath(filePath string) (*FileAttachment, error) {
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func(f *os.File) {
|
||||
_ = f.Close()
|
||||
}(f)
|
||||
|
||||
content, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewAttachmentFromFileContent(filePath, content)
|
||||
}
|
||||
@@ -24,12 +24,18 @@ type Destination struct {
|
||||
BccAddresses Addresses `json:"BccAddresses,omitempty"`
|
||||
}
|
||||
|
||||
type FileAttachment struct {
|
||||
Filename string `json:"Filename"`
|
||||
Content string `json:"Content"`
|
||||
}
|
||||
|
||||
type EmailRequest struct {
|
||||
Source string `json:"Source"`
|
||||
Destination Destination `json:"Destination"`
|
||||
Message Message `json:"Message"`
|
||||
ScheduledTime time.Time `json:"ScheduledTime,omitempty"`
|
||||
Catch bool `json:"Catch,omitempty"`
|
||||
Attachments []FileAttachment `json:"Attachments,omitempty"`
|
||||
Source string `json:"Source"`
|
||||
Destination Destination `json:"Destination"`
|
||||
Message Message `json:"Message"`
|
||||
ScheduledTime time.Time `json:"ScheduledTime,omitempty"`
|
||||
Catch bool `json:"Catch,omitempty"`
|
||||
}
|
||||
|
||||
type Email struct {
|
||||
|
||||
Reference in New Issue
Block a user