@@ -92,13 +92,11 @@ func (e *emailSender) sendMail(smtpServerAddr, message string) (err error) {
92
92
var c * smtp.Client
93
93
var auth sasl.Client
94
94
emailConf := e .conf
95
- //TLS Config
96
95
tlsConfig := & tls.Config {
97
96
ServerName : emailConf .SMTPAddr ,
98
97
}
99
98
switch emailConf .SMTPPort {
100
99
case "465" :
101
- //New TLS connection
102
100
c , err = smtp .DialTLS (smtpServerAddr , tlsConfig )
103
101
if err != nil {
104
102
return xerrors .Errorf ("Failed to create TLS connection to SMTP server: %w" , err )
@@ -111,16 +109,17 @@ func (e *emailSender) sendMail(smtpServerAddr, message string) (err error) {
111
109
}
112
110
defer c .Close ()
113
111
114
- if err = c .Hello ("localhost" ); err != nil {
115
- return xerrors .Errorf ("Failed to send Hello command: %w" , err )
116
- }
117
-
118
112
if ok , _ := c .Extension ("STARTTLS" ); ok {
119
- if err := c .StartTLS (tlsConfig ); err != nil {
120
- return xerrors .Errorf ("Failed to STARTTLS: %w" , err )
113
+ c , err = smtp .DialStartTLS (smtpServerAddr , tlsConfig )
114
+ if err != nil {
115
+ return xerrors .Errorf ("Failed to create STARTTLS connection to SMTP server: %w" , err )
121
116
}
122
117
}
123
118
119
+ if err = c .Hello ("localhost" ); err != nil {
120
+ return xerrors .Errorf ("Failed to send Hello command: %w" , err )
121
+ }
122
+
124
123
if ok , param := c .Extension ("AUTH" ); ok {
125
124
authList := strings .Split (param , " " )
126
125
auth = e .newSaslClient (authList )
0 commit comments