2020-05-13 12:07:44 +00:00
|
|
|
package alps
|
2019-12-03 15:27:49 +00:00
|
|
|
|
|
|
|
import (
|
2021-03-08 16:22:46 +00:00
|
|
|
"crypto/tls"
|
2019-12-03 15:27:49 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/emersion/go-smtp"
|
|
|
|
)
|
|
|
|
|
2019-12-16 11:51:42 +00:00
|
|
|
func (s *Server) dialSMTP() (*smtp.Client, error) {
|
|
|
|
if s.smtp.host == "" {
|
|
|
|
return nil, fmt.Errorf("SMTP is disabled")
|
2019-12-03 17:41:23 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:27:49 +00:00
|
|
|
var c *smtp.Client
|
|
|
|
var err error
|
|
|
|
if s.smtp.tls {
|
2021-03-08 16:22:46 +00:00
|
|
|
c, err = smtp.DialTLS(s.smtp.host, &tls.Config{InsecureSkipVerify: s.Options.SkipTlsVerification})
|
2019-12-03 15:27:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to connect to SMTPS server: %v", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c, err = smtp.Dial(s.smtp.host)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to connect to SMTP server: %v", err)
|
|
|
|
}
|
|
|
|
if !s.smtp.insecure {
|
|
|
|
if err := c.StartTLS(nil); err != nil {
|
|
|
|
c.Close()
|
|
|
|
return nil, fmt.Errorf("STARTTLS failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, err
|
|
|
|
}
|