feat: convert markdown to html
This commit is contained in:
22
email.go
22
email.go
@@ -1,12 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/resendlabs/resend-go"
|
||||
"github.com/yuin/goldmark"
|
||||
)
|
||||
|
||||
const TO_SEPARATOR = ","
|
||||
|
||||
// sendEmailSuccessMsg is the tea.Msg handled by Bubble Tea when the email has
|
||||
// been sent successfully.
|
||||
type sendEmailSuccessMsg struct{}
|
||||
@@ -26,7 +31,7 @@ func (m Model) sendEmailCmd() tea.Cmd {
|
||||
}
|
||||
attachments[i] = string(at)
|
||||
}
|
||||
err := sendEmail(m.From.Value(), m.To.Value(), m.Subject.Value(), m.Body.Value(), attachments)
|
||||
err := sendEmail(strings.Split(m.To.Value(), TO_SEPARATOR), m.From.Value(), m.Subject.Value(), m.Body.Value(), attachments)
|
||||
if err != nil {
|
||||
return sendEmailFailureMsg(err)
|
||||
}
|
||||
@@ -34,17 +39,24 @@ func (m Model) sendEmailCmd() tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func sendEmail(from, to, subject, body string, attachments []string) error {
|
||||
func sendEmail(to []string, from, subject, body string, attachments []string) error {
|
||||
client := resend.NewClient(os.Getenv(RESEND_API_KEY))
|
||||
|
||||
var html, text = bytes.NewBufferString(""), bytes.NewBufferString("")
|
||||
err := goldmark.Convert([]byte(body), html)
|
||||
if err != nil {
|
||||
text.WriteString(body)
|
||||
}
|
||||
|
||||
request := &resend.SendEmailRequest{
|
||||
From: from,
|
||||
To: []string{to},
|
||||
To: to,
|
||||
Subject: subject,
|
||||
Html: body,
|
||||
Html: html.String(),
|
||||
Text: text.String(),
|
||||
}
|
||||
|
||||
_, err := client.Emails.Send(request)
|
||||
_, err = client.Emails.Send(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user