mirror of
https://github.com/axllent/mailpit.git
synced 2026-06-27 22:46:09 +00:00
Improve error handling in autoForwardMessage and ensure proper client closure in createForwardingSMTPClient
This commit is contained in:
@@ -20,7 +20,7 @@ func autoForwardMessage(from string, data *[]byte) error {
|
||||
}
|
||||
|
||||
if err := forward(from, *data); err != nil {
|
||||
return errors.WithMessage(err, "[forward] error: %s")
|
||||
return fmt.Errorf("[forward] error: %w", err)
|
||||
}
|
||||
|
||||
logger.Log().Debugf(
|
||||
@@ -59,6 +59,7 @@ func createForwardingSMTPClient(config config.SMTPForwardConfigStruct, addr stri
|
||||
// Set the hostname for HELO/EHLO
|
||||
if hostname, err := os.Hostname(); err == nil {
|
||||
if err := client.Hello(hostname); err != nil {
|
||||
_ = client.Close()
|
||||
return nil, fmt.Errorf("error saying HELO/EHLO to %s: %v", addr, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,10 +882,14 @@ func (s *session) readData() ([]byte, error) {
|
||||
// TODO: Work out what to do with multiple to addresses.
|
||||
func (s *session) makeHeaders(to []string) []byte {
|
||||
var buffer bytes.Buffer
|
||||
if len(to) == 0 {
|
||||
return buffer.Bytes()
|
||||
}
|
||||
|
||||
now := time.Now().Format("Mon, 2 Jan 2006 15:04:05 -0700 (MST)")
|
||||
buffer.WriteString(fmt.Sprintf("Received: from %s (%s [%s])\r\n", s.remoteName, s.remoteHost, s.remoteIP))
|
||||
buffer.WriteString(fmt.Sprintf(" by %s (%s) with SMTP\r\n", s.srv.Hostname, s.srv.AppName))
|
||||
buffer.WriteString(fmt.Sprintf(" for <%s>; %s\r\n", to[0], now))
|
||||
fmt.Fprintf(&buffer, "Received: from %s (%s [%s])\r\n", s.remoteName, s.remoteHost, s.remoteIP)
|
||||
fmt.Fprintf(&buffer, " by %s (%s) with SMTP\r\n", s.srv.Hostname, s.srv.AppName)
|
||||
fmt.Fprintf(&buffer, " for <%s>; %s\r\n", to[0], now)
|
||||
return buffer.Bytes()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user