-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (54 loc) · 1.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"context"
"path/filepath"
"strings"
"bookdrop/internal/configa"
"os"
"github.com/charmbracelet/log"
"github.com/resend/resend-go/v2"
)
func main() {
log.SetReportTimestamp(false)
log.SetReportCaller(false)
if os.Getenv("BOOKDROP_DEBUG") != "true" {
log.SetLevel(log.DebugLevel)
log.Debug("Debug Enabled!")
}
if len(os.Args) < 2 {
log.Fatal("No Books Attached! Please Provide a Path!")
}
configa.Configure()
ctx := context.TODO()
args := os.Args
log.Debugf("Unmarshalled yaml config:\n%+v\n", configa.Config)
log.Debug(configa.Config.ApiKey)
if configa.Config.ApiKey == "" {
log.Fatal("Api Key is missing! Please set using the environmental variable `RESEND_API_KEY`")
}
f, err := os.ReadFile(args[1])
if err != nil {
log.Fatal(err)
}
fileName := filepath.Base(args[1])
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
client := resend.NewClient(configa.Config.ApiKey)
// Create attachments objects
BookAttachment := &resend.Attachment{
Content: f,
Filename: fileName,
}
params := &resend.SendEmailRequest{
To: []string{configa.Config.DefaultReciever},
From: configa.Config.DefaultSender,
Text: "Book Drop!",
Html: "<strong>Books attached to the email Boss !!</strong>",
Subject: "Book Drop Incoming!",
Attachments: []*resend.Attachment{BookAttachment},
}
sent, err := client.Emails.SendWithContext(ctx, params)
if err != nil {
log.Fatal(err)
}
log.Print(sent.Id)
}