mirror of
https://github.com/ivabus/pop
synced 2024-11-10 02:25:19 +03:00
fix: seed attachments from command line
This commit is contained in:
parent
bb54eb503f
commit
50e40f8cc2
42
email.go
42
email.go
|
@ -43,6 +43,28 @@ func sendEmail(to []string, from, subject, body string, paths []string) error {
|
||||||
// If the conversion fails, we'll simply send the plain-text body.
|
// If the conversion fails, we'll simply send the plain-text body.
|
||||||
_ = goldmark.Convert([]byte(body), html)
|
_ = goldmark.Convert([]byte(body), html)
|
||||||
|
|
||||||
|
request := &resend.SendEmailRequest{
|
||||||
|
From: from,
|
||||||
|
To: to,
|
||||||
|
Subject: subject,
|
||||||
|
Html: html.String(),
|
||||||
|
Text: body,
|
||||||
|
Attachments: makeAttachments(paths),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := client.Emails.Send(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeAttachments(paths []string) []resend.Attachment {
|
||||||
|
if len(paths) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
attachments := make([]resend.Attachment, len(paths))
|
attachments := make([]resend.Attachment, len(paths))
|
||||||
for i, a := range paths {
|
for i, a := range paths {
|
||||||
f, err := os.ReadFile(a)
|
f, err := os.ReadFile(a)
|
||||||
|
@ -55,23 +77,5 @@ func sendEmail(to []string, from, subject, body string, paths []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(attachments) == 0 {
|
return attachments
|
||||||
attachments = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
request := &resend.SendEmailRequest{
|
|
||||||
From: from,
|
|
||||||
To: to,
|
|
||||||
Subject: subject,
|
|
||||||
Html: html.String(),
|
|
||||||
Text: body,
|
|
||||||
Attachments: attachments,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := client.Emails.Send(request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
9
main.go
9
main.go
|
@ -54,10 +54,11 @@ var rootCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
p := tea.NewProgram(NewModel(resend.SendEmailRequest{
|
p := tea.NewProgram(NewModel(resend.SendEmailRequest{
|
||||||
From: from,
|
From: from,
|
||||||
To: to,
|
To: to,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Text: body,
|
Text: body,
|
||||||
|
Attachments: makeAttachments(attachments),
|
||||||
}))
|
}))
|
||||||
m, err := p.Run()
|
m, err := p.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
4
model.go
4
model.go
|
@ -127,6 +127,10 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
attachments.SetStatusBarItemName("attachment", "attachments")
|
attachments.SetStatusBarItemName("attachment", "attachments")
|
||||||
attachments.SetShowPagination(false)
|
attachments.SetShowPagination(false)
|
||||||
|
|
||||||
|
for _, a := range defaults.Attachments {
|
||||||
|
attachments.InsertItem(0, attachment(a.Filename))
|
||||||
|
}
|
||||||
|
|
||||||
picker := filepicker.New()
|
picker := filepicker.New()
|
||||||
picker.CurrentDirectory, _ = os.UserHomeDir()
|
picker.CurrentDirectory, _ = os.UserHomeDir()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue