Skip to content

Commit

Permalink
fix(smtp): use param props from params arg
Browse files Browse the repository at this point in the history
was ignoring encryption, subject, fromname and fromaddress
  • Loading branch information
JosephKav authored Jan 19, 2024
1 parent 3c77fd5 commit 60588bb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pkg/services/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ func (service *Service) Send(message string, params *types.Params) error {
return fail(FailApplySendParams, err)
}

client, err := getClientConnection(service.config)
client, err := getClientConnection(service.config, config.Encryption)
if err != nil {
return fail(FailGetSMTPClient, err)
}

return service.doSend(client, message, &config)
}

func getClientConnection(config *Config) (*smtp.Client, error) {
func getClientConnection(config *Config, encryption encMethod) (*smtp.Client, error) {

var conn net.Conn
var err error

addr := fmt.Sprintf("%s:%d", config.Host, config.Port)

if useImplicitTLS(config.Encryption, config.Port) {
if useImplicitTLS(encryption, config.Port) {
conn, err = tls.Dial("tcp", addr, &tls.Config{
ServerName: config.Host,
})
Expand Down Expand Up @@ -206,7 +206,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(toAddress, config)); err != nil {
return err
}

Expand All @@ -228,9 +228,7 @@ 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

func (service *Service) getHeaders(toAddress string, conf *Config) map[string]string {
var contentType string
if conf.UseHTML {
contentType = fmt.Sprintf(contentMultipart, service.multipartBoundary)
Expand All @@ -239,7 +237,7 @@ func (service *Service) getHeaders(toAddress string, subject string) map[string]
}

return map[string]string{
"Subject": subject,
"Subject": conf.Subject,
"Date": time.Now().Format(time.RFC1123Z),
"To": toAddress,
"From": fmt.Sprintf("%s <%s>", conf.FromName, conf.FromAddress),
Expand Down

0 comments on commit 60588bb

Please sign in to comment.