Compare commits

...

2 commits
v1.1.1 ... main

16
smtp.go
View file

@ -214,7 +214,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
for { for {
line, err := textProto.ReadLine() line, err := textProto.ReadLine()
fmt.Println(line)
if err != nil { if err != nil {
_ = textProto.PrintfLine("421 4.7.0 Temporary server error") _ = textProto.PrintfLine("421 4.7.0 Temporary server error")
_ = conn.Close() _ = conn.Close()
@ -296,8 +295,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
} }
} }
case strings.HasPrefix(line, "AUTH"): case strings.HasPrefix(line, "AUTH"):
fmt.Println("It's about time")
if !isSubmission { if !isSubmission {
err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port") err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port")
if err != nil { if err != nil {
@ -329,7 +326,7 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
} else { } else {
checkAddress, err := fr.auth.Authenticate(strings.TrimPrefix(line, "AUTH "), textProto) checkAddress, err := fr.auth.Authenticate(strings.TrimPrefix(line, "AUTH "), textProto)
if err != nil { if err != nil {
_ = textProto.PrintfLine("421 4.7.0 Temporary server error") _ = textProto.PrintfLine(err.Error())
_ = conn.Close() _ = conn.Close()
return return
} }
@ -593,7 +590,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
Host: strings.Split(conn.RemoteAddr().String(), ":")[0], Host: strings.Split(conn.RemoteAddr().String(), ":")[0],
} }
go sendEmail(SenderArgs{ go sendEmail(SenderArgs{
Hostname: fr.hostname,
EnforceTLS: fr.enforceTLS, EnforceTLS: fr.enforceTLS,
}, mail, fr.database, queueID) }, mail, fr.database, queueID)
@ -622,7 +618,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
// SenderArgs is a struct that represents the arguments for the Sender // SenderArgs is a struct that represents the arguments for the Sender
type SenderArgs struct { type SenderArgs struct {
Hostname string
EnforceTLS bool EnforceTLS bool
} }
@ -653,7 +648,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
return errors.New("unexpected greeting - " + line) return errors.New("unexpected greeting - " + line)
} }
err = textConn.PrintfLine("EHLO %s", args.Hostname) err = textConn.PrintfLine("EHLO %s", mxHost)
if err != nil { if err != nil {
return err return err
} }
@ -687,16 +682,11 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
InsecureSkipVerify: false, InsecureSkipVerify: false,
}) })
err = tlsConn.Handshake()
if err != nil {
return err
}
textConn = textproto.NewConn(tlsConn) textConn = textproto.NewConn(tlsConn)
// Just use HELO, no point using EHLO when we already have all the capabilities // Just use HELO, no point using EHLO when we already have all the capabilities
// This also gets us out of using readMultilineCodeResponse // This also gets us out of using readMultilineCodeResponse
err = textConn.PrintfLine("HELO %s", args.Hostname) err = textConn.PrintfLine("HELO %s", mxHost)
if err != nil { if err != nil {
return err return err
} }