log all smtp connection errors
This commit is contained in:
2
go.mod
2
go.mod
@@ -20,7 +20,7 @@ require (
|
|||||||
gitlab.com/etke.cc/go/logger v1.1.0
|
gitlab.com/etke.cc/go/logger v1.1.0
|
||||||
gitlab.com/etke.cc/go/mxidwc v1.0.0
|
gitlab.com/etke.cc/go/mxidwc v1.0.0
|
||||||
gitlab.com/etke.cc/go/secgen v1.1.1
|
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/go/validator v1.0.6
|
||||||
gitlab.com/etke.cc/linkpearl v0.0.0-20221116205701-65547c5608e6
|
gitlab.com/etke.cc/linkpearl v0.0.0-20221116205701-65547c5608e6
|
||||||
maunium.net/go/mautrix v0.12.3
|
maunium.net/go/mautrix v0.12.3
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -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/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 h1:RmKOki725HIhWJHzPtAc9X4YvBneczndchpMgoDkE8w=
|
||||||
gitlab.com/etke.cc/go/secgen v1.1.1/go.mod h1:3pJqRGeWApzx7qXjABqz2o2SMCNpKSZao/gXVdasqE8=
|
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.2 h1:Jg+J/zgx77wqJ9J5L5dlKFoQLka6yYTXa2wf+GNhjnQ=
|
||||||
gitlab.com/etke.cc/go/trysmtp v1.1.1/go.mod h1:lOO7tTdAE0a3ETV3wN3GJ7I1Tqewu7YTpPWaOmTteV0=
|
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 h1:w0Muxf9Pqw7xvF7NaaswE6d7r9U3nB2t2l5PnFMrecQ=
|
||||||
gitlab.com/etke.cc/go/validator v1.0.6/go.mod h1:Id0SxRj0J3IPhiKlj0w1plxVLZfHlkwipn7HfRZsDts=
|
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=
|
gitlab.com/etke.cc/linkpearl v0.0.0-20221116205701-65547c5608e6 h1:+HDT2/bx3Hug++aeDE/PaoRRcnKdYzEm6i2RlOAzPXo=
|
||||||
|
|||||||
@@ -93,10 +93,13 @@ func (m *mailServer) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session,
|
|||||||
func (m *mailServer) SendEmail(from, to, data string) error {
|
func (m *mailServer) SendEmail(from, to, data string) error {
|
||||||
m.log.Debug("Sending email from %s to %s", from, to)
|
m.log.Debug("Sending email from %s to %s", from, to)
|
||||||
conn, err := trysmtp.Connect(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)
|
m.log.Error("cannot connect to SMTP server of %s: %v", to, err)
|
||||||
return 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()
|
defer conn.Close()
|
||||||
|
|
||||||
var w io.WriteCloser
|
var w io.WriteCloser
|
||||||
|
|||||||
11
vendor/gitlab.com/etke.cc/go/trysmtp/client.go
generated
vendored
11
vendor/gitlab.com/etke.cc/go/trysmtp/client.go
generated
vendored
@@ -12,15 +12,16 @@ import (
|
|||||||
var SMTPAddrs = []string{":25", ":587", ":465"}
|
var SMTPAddrs = []string{":25", ":587", ":465"}
|
||||||
|
|
||||||
// Connect to SMTP server and call MAIL and RCPT commands
|
// 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) {
|
func Connect(from, to string) (*smtp.Client, error) {
|
||||||
localname := strings.SplitN(from, "@", 2)[1]
|
localname := strings.SplitN(from, "@", 2)[1]
|
||||||
hostname := strings.SplitN(to, "@", 2)[1]
|
hostname := strings.SplitN(to, "@", 2)[1]
|
||||||
client, err := initClient(localname, hostname)
|
client, cerr := initClient(localname, hostname)
|
||||||
if err != nil {
|
if client == nil {
|
||||||
return nil, err
|
return nil, cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.Mail(from)
|
err := client.Mail(from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Close()
|
client.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -32,7 +33,7 @@ func Connect(from, to string) (*smtp.Client, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
func unwrapErrors(errs []error) error {
|
func unwrapErrors(errs []error) error {
|
||||||
|
|||||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -134,7 +134,7 @@ gitlab.com/etke.cc/go/mxidwc
|
|||||||
# gitlab.com/etke.cc/go/secgen v1.1.1
|
# gitlab.com/etke.cc/go/secgen v1.1.1
|
||||||
## explicit; go 1.19
|
## explicit; go 1.19
|
||||||
gitlab.com/etke.cc/go/secgen
|
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
|
## explicit; go 1.17
|
||||||
gitlab.com/etke.cc/go/trysmtp
|
gitlab.com/etke.cc/go/trysmtp
|
||||||
# gitlab.com/etke.cc/go/validator v1.0.6
|
# gitlab.com/etke.cc/go/validator v1.0.6
|
||||||
|
|||||||
Reference in New Issue
Block a user