Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UseHTML and UseStartTLS parameters for SMTP provider #223

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ smtp:
- to@email.com
smtp_format: "{{data}}"
subject: "Email subject"
smtp_html: false
smtp_disable_starttls: false

googlechat:
- id: "gc"
Expand Down
25 changes: 15 additions & 10 deletions pkg/providers/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package smtp

import (
"fmt"
"strconv"
"strings"

"github.com/containrrr/shoutrrr"
Expand All @@ -19,14 +20,16 @@ type Provider struct {
}

type Options struct {
ID string `yaml:"id,omitempty"`
Server string `yaml:"smtp_server,omitempty"`
Username string `yaml:"smtp_username,omitempty"`
Password string `yaml:"smtp_password,omitempty"`
FromAddress string `yaml:"from_address,omitempty"`
SMTPCC []string `yaml:"smtp_cc,omitempty"`
SMTPFormat string `yaml:"smtp_format,omitempty"`
Subject string `yaml:"subject,omitempty"`
ID string `yaml:"id,omitempty"`
Server string `yaml:"smtp_server,omitempty"`
Username string `yaml:"smtp_username,omitempty"`
Password string `yaml:"smtp_password,omitempty"`
FromAddress string `yaml:"from_address,omitempty"`
SMTPCC []string `yaml:"smtp_cc,omitempty"`
SMTPFormat string `yaml:"smtp_format,omitempty"`
Subject string `yaml:"subject,omitempty"`
HTML bool `yaml:"smtp_html,omitempty"`
DisableStartTLS bool `yaml:"smtp_disable_starttls,omitempty"`
}

func New(options []*Options, ids []string) (*Provider, error) {
Expand All @@ -48,8 +51,10 @@ func (p *Provider) Send(message, CliFormat string) error {
p.counter++
for _, pr := range p.SMTP {
msg := utils.FormatMessage(message, utils.SelectFormat(CliFormat, pr.SMTPFormat), p.counter)

url := fmt.Sprintf("smtp://%s:%s@%s/?fromAddress=%s&toAddresses=%s&subject=%s", pr.Username, pr.Password, pr.Server, pr.FromAddress, strings.Join(pr.SMTPCC, ","), pr.Subject)
url := fmt.Sprintf(
"smtp://%s:%s@%s/?fromAddress=%s&toAddresses=%s&subject=%s&UseHTML=%s&UseStartTLS=%s",
pr.Username, pr.Password, pr.Server, pr.FromAddress, strings.Join(pr.SMTPCC, ","), pr.Subject, strconv.FormatBool(pr.HTML), strconv.FormatBool(!pr.DisableStartTLS),
)
err := shoutrrr.Send(url, msg)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("failed to send smtp notification for id: %s ", pr.ID))
Expand Down