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

fix(smtp): allow usehtml to be set in params #388

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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