diff --git a/pkg/services/smtp/smtp.go b/pkg/services/smtp/smtp.go index 1a09b577..b4d8226f 100644 --- a/pkg/services/smtp/smtp.go +++ b/pkg/services/smtp/smtp.go @@ -71,7 +71,7 @@ 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) } @@ -79,14 +79,14 @@ func (service *Service) Send(message string, params *types.Params) error { 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, }) @@ -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 } @@ -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) @@ -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),