Skip to content

Commit

Permalink
fix(smtp): allow usehtml to be set in params
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Sep 16, 2023
1 parent a59c927 commit 689c66a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 6 additions & 10 deletions pkg/services/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (service *Service) sendToRecipient(client *smtp.Client, toAddress string, c
return fail(FailOpenDataStream, err)
}

if err := writeHeaders(wc, service.getHeaders(toAddress, config.Subject)); err != nil {
if err := writeHeaders(wc, service.getHeaders(config, toAddress)); err != nil {
return err
}

Expand All @@ -227,21 +227,17 @@ func (service *Service) sendToRecipient(client *smtp.Client, toAddress string, c
return nil
}

func (service *Service) getHeaders(toAddress string, subject string) map[string]string {
conf := service.config

var contentType string
if conf.UseHTML {
func (service *Service) getHeaders(config *Config, toAddress string) map[string]string {
contentType := contentPlain
if config.UseHTML {
contentType = fmt.Sprintf(contentMultipart, service.multipartBoundary)
} else {
contentType = contentPlain
}

return map[string]string{
"Subject": subject,
"Subject": config.Subject,
"Date": time.Now().Format(time.RFC1123Z),
"To": toAddress,
"From": fmt.Sprintf("%s <%s>", conf.FromName, conf.FromAddress),
"From": fmt.Sprintf("%s <%s>", config.FromName, config.FromAddress),
"MIME-version": "1.0",
"Content-Type": contentType,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/smtp/smtp_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ type Config struct {
ClientHost string `desc:"The client host name sent to the SMTP server during HELLO phase. If set to \"auto\" it will use the OS hostname" key:"clienthost" default:"localhost"`
}

// GetURL returns a URL representation of it's current field values
// GetURL returns a URL representation of its current field values
func (config *Config) GetURL() *url.URL {
resolver := format.NewPropKeyResolver(config)
return config.getURL(&resolver)
}

// SetURL updates a ServiceConfig from a URL representation of it's field values
// SetURL updates a ServiceConfig from a URL representation of its field values
func (config *Config) SetURL(url *url.URL) error {
resolver := format.NewPropKeyResolver(config)
return config.setURL(&resolver, url)
Expand Down Expand Up @@ -100,7 +100,7 @@ func (config *Config) FixEmailTags() {
}

// Enums returns the fields that should use a corresponding EnumFormatter to Print/Parse their values
func (config Config) Enums() map[string]types.EnumFormatter {
func (config *Config) Enums() map[string]types.EnumFormatter {
return map[string]types.EnumFormatter{
"Auth": AuthTypes.Enum,
"Encryption": EncMethods.Enum,
Expand Down

0 comments on commit 689c66a

Please sign in to comment.