log all smtp connection errors

This commit is contained in:
Aine
2023-02-11 21:20:41 +02:00
parent 6d55ee40ed
commit 7d0d8cd2e6
5 changed files with 14 additions and 10 deletions

2
go.mod
View File

@@ -20,7 +20,7 @@ require (
gitlab.com/etke.cc/go/logger v1.1.0
gitlab.com/etke.cc/go/mxidwc v1.0.0
gitlab.com/etke.cc/go/secgen v1.1.1
gitlab.com/etke.cc/go/trysmtp v1.1.1
gitlab.com/etke.cc/go/trysmtp v1.1.2
gitlab.com/etke.cc/go/validator v1.0.6
gitlab.com/etke.cc/linkpearl v0.0.0-20221116205701-65547c5608e6
maunium.net/go/mautrix v0.12.3

4
go.sum
View File

@@ -103,8 +103,8 @@ gitlab.com/etke.cc/go/mxidwc v1.0.0 h1:6EAlJXvs3nU4RaMegYq6iFlyVvLw7JZYnZmNCGMYQ
gitlab.com/etke.cc/go/mxidwc v1.0.0/go.mod h1:E/0kh45SAN9+ntTG0cwkAEKdaPxzvxVmnjwivm9nmz8=
gitlab.com/etke.cc/go/secgen v1.1.1 h1:RmKOki725HIhWJHzPtAc9X4YvBneczndchpMgoDkE8w=
gitlab.com/etke.cc/go/secgen v1.1.1/go.mod h1:3pJqRGeWApzx7qXjABqz2o2SMCNpKSZao/gXVdasqE8=
gitlab.com/etke.cc/go/trysmtp v1.1.1 h1:4mbkfsfipidG2eO8/zSozJ78Vv/lRAcdznvjK0fMVuo=
gitlab.com/etke.cc/go/trysmtp v1.1.1/go.mod h1:lOO7tTdAE0a3ETV3wN3GJ7I1Tqewu7YTpPWaOmTteV0=
gitlab.com/etke.cc/go/trysmtp v1.1.2 h1:Jg+J/zgx77wqJ9J5L5dlKFoQLka6yYTXa2wf+GNhjnQ=
gitlab.com/etke.cc/go/trysmtp v1.1.2/go.mod h1:lOO7tTdAE0a3ETV3wN3GJ7I1Tqewu7YTpPWaOmTteV0=
gitlab.com/etke.cc/go/validator v1.0.6 h1:w0Muxf9Pqw7xvF7NaaswE6d7r9U3nB2t2l5PnFMrecQ=
gitlab.com/etke.cc/go/validator v1.0.6/go.mod h1:Id0SxRj0J3IPhiKlj0w1plxVLZfHlkwipn7HfRZsDts=
gitlab.com/etke.cc/linkpearl v0.0.0-20221116205701-65547c5608e6 h1:+HDT2/bx3Hug++aeDE/PaoRRcnKdYzEm6i2RlOAzPXo=

View File

@@ -93,10 +93,13 @@ func (m *mailServer) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session,
func (m *mailServer) SendEmail(from, to, data string) error {
m.log.Debug("Sending email from %s to %s", from, to)
conn, err := trysmtp.Connect(from, to)
if err != nil {
if conn == nil {
m.log.Error("cannot connect to SMTP server of %s: %v", to, err)
return err
}
if err != nil {
m.log.Warn("connection to the SMTP server of %s returned the following non-fatal error(-s): %v", err)
}
defer conn.Close()
var w io.WriteCloser

View File

@@ -12,15 +12,16 @@ import (
var SMTPAddrs = []string{":25", ":587", ":465"}
// Connect to SMTP server and call MAIL and RCPT commands
// NOTE: check if client is not nil, because it can return non-fatal errors with initialized client
func Connect(from, to string) (*smtp.Client, error) {
localname := strings.SplitN(from, "@", 2)[1]
hostname := strings.SplitN(to, "@", 2)[1]
client, err := initClient(localname, hostname)
if err != nil {
return nil, err
client, cerr := initClient(localname, hostname)
if client == nil {
return nil, cerr
}
err = client.Mail(from)
err := client.Mail(from)
if err != nil {
client.Close()
return nil, err
@@ -32,7 +33,7 @@ func Connect(from, to string) (*smtp.Client, error) {
return nil, err
}
return client, nil
return client, cerr
}
func unwrapErrors(errs []error) error {

2
vendor/modules.txt vendored
View File

@@ -134,7 +134,7 @@ gitlab.com/etke.cc/go/mxidwc
# gitlab.com/etke.cc/go/secgen v1.1.1
## explicit; go 1.19
gitlab.com/etke.cc/go/secgen
# gitlab.com/etke.cc/go/trysmtp v1.1.1
# gitlab.com/etke.cc/go/trysmtp v1.1.2
## explicit; go 1.17
gitlab.com/etke.cc/go/trysmtp
# gitlab.com/etke.cc/go/validator v1.0.6