add support for better ssl/tls handling
This commit is contained in:
@@ -50,14 +50,23 @@ func SendUpdate(subject, body string) (string, error) {
|
|||||||
func send(subject, body, recipient string) bool {
|
func send(subject, body, recipient string) bool {
|
||||||
cfg := config.Current
|
cfg := config.Current
|
||||||
|
|
||||||
client, err := mail.NewClient(
|
var opts []mail.ClientOption
|
||||||
cfg.SMTPServer,
|
opts = append(opts,
|
||||||
mail.WithPort(cfg.SMTPPort),
|
mail.WithPort(cfg.SMTPPort),
|
||||||
mail.WithSMTPAuth(mail.SMTPAuthPlain),
|
mail.WithSMTPAuth(mail.SMTPAuthPlain),
|
||||||
mail.WithUsername(cfg.SMTPUser),
|
mail.WithUsername(cfg.SMTPUser),
|
||||||
mail.WithPassword(cfg.SMTPPassword),
|
mail.WithPassword(cfg.SMTPPassword),
|
||||||
mail.WithTimeout(10*time.Second),
|
mail.WithTimeout(10*time.Second),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Use SSL for port 465, STARTTLS for others
|
||||||
|
if cfg.SMTPPort == 465 {
|
||||||
|
opts = append(opts, mail.WithSSL())
|
||||||
|
} else {
|
||||||
|
opts = append(opts, mail.WithTLSPolicy(mail.TLSMandatory))
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := mail.NewClient(cfg.SMTPServer, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to create mail client: %v", err)
|
log.Printf("Failed to create mail client: %v", err)
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user