Skip to content

Commit 63a8975

Browse files
committed
feat: Allow plaintext e-mails for SMTP
Adds `--plaintext` flag which allows sending e-mails in plaintext with SMTP method. Not implemented for the Resend method.
1 parent ef985e9 commit 63a8975

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

email.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (m Model) sendEmailCmd() tea.Cmd {
4242
bcc := strings.Split(m.Bcc.Value(), ToSeparator)
4343
switch m.DeliveryMethod {
4444
case SMTP:
45-
err = sendSMTPEmail(to, cc, bcc, m.From.Value(), m.Subject.Value(), m.Body.Value(), attachments)
45+
err = sendSMTPEmail(to, cc, bcc, m.From.Value(), m.Subject.Value(), m.Body.Value(), plaintext, attachments)
4646
case Resend:
4747
err = sendResendEmail(to, cc, bcc, m.From.Value(), m.Subject.Value(), m.Body.Value(), attachments)
4848
default:
@@ -63,7 +63,7 @@ const gmailSuffix = "@gmail.com"
6363
const gmailSMTPHost = "smtp.gmail.com"
6464
const gmailSMTPPort = 587
6565

66-
func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments []string) error {
66+
func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, plaintext bool, attachments []string) error {
6767
server := mail.NewSMTPClient()
6868

6969
var err error
@@ -115,7 +115,7 @@ func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments
115115
html := bytes.NewBufferString("")
116116
convertErr := goldmark.Convert([]byte(body), html)
117117

118-
if convertErr != nil {
118+
if (plaintext) || (convertErr != nil) {
119119
email.SetBody(mail.TextPlain, body)
120120
} else {
121121
email.SetBody(mail.TextHTML, html.String())

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var (
5656
bcc []string
5757
subject string
5858
body string
59+
plaintext bool
5960
attachments []string
6061
preview bool
6162
unsafe bool
@@ -119,7 +120,7 @@ var rootCmd = &cobra.Command{
119120
var err error
120121
switch deliveryMethod {
121122
case SMTP:
122-
err = sendSMTPEmail(to, cc, bcc, from, subject, body, attachments)
123+
err = sendSMTPEmail(to, cc, bcc, from, subject, body, plaintext, attachments)
123124
case Resend:
124125
err = sendResendEmail(to, cc, bcc, from, subject, body, attachments)
125126
default:
@@ -201,6 +202,7 @@ func init() {
201202
rootCmd.Flags().StringSliceVarP(&attachments, "attach", "a", []string{}, "Email's attachments")
202203
rootCmd.Flags().StringSliceVarP(&to, "to", "t", []string{}, "Recipients")
203204
rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents")
205+
rootCmd.Flags().BoolVar(&plaintext, "plaintext", false, "Whether to send email in plaintext")
204206
envFrom := os.Getenv(PopFrom)
205207
rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender"+commentStyle.Render("($"+PopFrom+")"))
206208
rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject")

0 commit comments

Comments
 (0)