From b420b7e9c6228ec1fea4f1092f60a221d458f836 Mon Sep 17 00:00:00 2001 From: dexhorthy Date: Mon, 10 Feb 2025 12:42:52 -0800 Subject: [PATCH] support for replyto header --- email.go | 1 + main.go | 7 +++++++ model.go | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/email.go b/email.go index 3b4efb2..1d05457 100644 --- a/email.go +++ b/email.go @@ -154,6 +154,7 @@ func sendResendEmail(to, _, _ []string, from, subject, body string, attachments request := &resend.SendEmailRequest{ From: from, + ReplyTo: replyTo, To: to, Subject: subject, Cc: cc, diff --git a/main.go b/main.go index 00c7bc7..150c0a1 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,9 @@ const ResendAPIKey = "RESEND_API_KEY" //nolint:gosec // PopFrom is the environment variable that sets the default "from" address. const PopFrom = "POP_FROM" +// PopReplyTo is the environment variable that sets the default reply-to address. +const PopReplyTo = "POP_REPLY_TO" + // PopSignature is the environment variable that sets the default signature. const PopSignature = "POP_SIGNATURE" @@ -51,6 +54,7 @@ const PopSMTPInsecureSkipVerify = "POP_SMTP_INSECURE_SKIP_VERIFY" var ( from string + replyTo string to []string cc []string bcc []string @@ -137,6 +141,7 @@ var rootCmd = &cobra.Command{ p := tea.NewProgram(NewModel(resend.SendEmailRequest{ From: from, + ReplyTo: replyTo, To: to, Bcc: bcc, Cc: cc, @@ -203,6 +208,8 @@ func init() { rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents") envFrom := os.Getenv(PopFrom) rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender"+commentStyle.Render("($"+PopFrom+")")) + envReplyTo := os.Getenv(PopReplyTo) + rootCmd.Flags().StringVarP(&replyTo, "reply-to", "R", envReplyTo, "Email's reply-to address"+commentStyle.Render("($"+PopReplyTo+")")) rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject") rootCmd.Flags().BoolVar(&preview, "preview", false, "Whether to preview the email before sending") envUnsafe := os.Getenv(PopUnsafeHTML) == "true" diff --git a/model.go b/model.go index 244fdfc..077b41e 100644 --- a/model.go +++ b/model.go @@ -58,6 +58,8 @@ type Model struct { // From represents the sender's email address. From textinput.Model + // ReplyTo represents the reply-to email address. + ReplyTo textinput.Model // To represents the recipient's email address. // This can be a comma-separated list of addresses. To textinput.Model @@ -96,6 +98,16 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M from.PlaceholderStyle = placeholderStyle from.SetValue(defaults.From) + replyTo := textinput.New() + replyTo.Prompt = "Reply-To " + replyTo.Placeholder = "reply@example.com" + replyTo.PromptStyle = labelStyle.Copy() + replyTo.PromptStyle = labelStyle + replyTo.TextStyle = textStyle + replyTo.Cursor.Style = cursorStyle + replyTo.PlaceholderStyle = placeholderStyle + replyTo.SetValue(defaults.ReplyTo) + to := textinput.New() to.Prompt = "To " to.PromptStyle = labelStyle.Copy() @@ -192,6 +204,7 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M m := Model{ state: state, From: from, + ReplyTo: replyTo, To: to, showCc: len(cc.Value()) > 0 || len(bcc.Value()) > 0, Cc: cc, @@ -440,6 +453,8 @@ func (m Model) View() string { s.WriteString(m.From.View()) s.WriteString("\n") + s.WriteString(m.ReplyTo.View()) + s.WriteString("\n") s.WriteString(m.To.View()) s.WriteString("\n") if m.showCc {