mirror of
https://github.com/ivabus/pop
synced 2024-12-04 22:15:08 +03:00
feat: send plain-text if Convert
fails
This commit is contained in:
parent
71008451b1
commit
ea8aa49cde
1 changed files with 5 additions and 7 deletions
12
email.go
12
email.go
|
@ -39,11 +39,9 @@ func (m Model) sendEmailCmd() tea.Cmd {
|
||||||
func sendEmail(to []string, from, subject, body string, paths []string) error {
|
func sendEmail(to []string, from, subject, body string, paths []string) error {
|
||||||
client := resend.NewClient(os.Getenv(RESEND_API_KEY))
|
client := resend.NewClient(os.Getenv(RESEND_API_KEY))
|
||||||
|
|
||||||
var html, text = bytes.NewBufferString(""), bytes.NewBufferString("")
|
html := bytes.NewBufferString("")
|
||||||
err := goldmark.Convert([]byte(body), html)
|
// If the conversion fails, we'll simply send the plain-text body.
|
||||||
if err != nil {
|
_ = goldmark.Convert([]byte(body), html)
|
||||||
text.WriteString(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
attachments := make([]resend.Attachment, len(paths))
|
attachments := make([]resend.Attachment, len(paths))
|
||||||
for i, a := range paths {
|
for i, a := range paths {
|
||||||
|
@ -66,11 +64,11 @@ func sendEmail(to []string, from, subject, body string, paths []string) error {
|
||||||
To: to,
|
To: to,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Html: html.String(),
|
Html: html.String(),
|
||||||
Text: text.String(),
|
Text: body,
|
||||||
Attachments: attachments,
|
Attachments: attachments,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Emails.Send(request)
|
_, err := client.Emails.Send(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue