2020-10-08 22:36:17 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
"net"
|
2021-07-30 23:20:49 +02:00
|
|
|
"time"
|
2021-07-31 13:26:20 +02:00
|
|
|
|
2020-10-08 22:36:17 +02:00
|
|
|
)
|
|
|
|
|
2021-07-30 23:20:49 +02:00
|
|
|
|
|
|
|
|
2020-10-08 22:36:17 +02:00
|
|
|
func mailHandler(origin net.Addr, from string, to []string, data []byte) {
|
|
|
|
SmtpSession := new(Session)
|
|
|
|
|
|
|
|
log.Printf("Received mail from %s for %q from %s", from, to, origin.String())
|
|
|
|
log.Println(" Recipients: ", to)
|
|
|
|
|
|
|
|
for _, rcptTo := range to {
|
|
|
|
SmtpSession.Reset()
|
|
|
|
|
|
|
|
if rcptErr := SmtpSession.Rcpt(rcptTo); rcptErr == nil {
|
|
|
|
SmtpSession.MailFrom = from
|
|
|
|
if dataErr := SmtpSession.Data(bytes.NewReader(data)); dataErr != nil {
|
|
|
|
log.Println("Problem Saving Message: ", dataErr.Error())
|
|
|
|
}
|
2021-07-31 13:26:20 +02:00
|
|
|
|
2020-10-08 22:36:17 +02:00
|
|
|
} else {
|
|
|
|
log.Println(rcptErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-30 23:20:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
func handlerRcpt(remoteAddr net.Addr, from string, to string) bool {
|
|
|
|
|
|
|
|
log.Println("CHECK #2 Rcpt to:", to)
|
|
|
|
if !SmtpBackend.CheckValidRcpt(to) {
|
2021-07-31 13:26:20 +02:00
|
|
|
log.Printf("%s [ %s -> %s ] %s BAD!!!!", "YU NO MAIL!!! WE NU RELAY!!! ", from, to, remoteAddr.String() )
|
2021-07-30 23:20:49 +02:00
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
return false
|
|
|
|
}else{
|
2021-07-31 13:26:20 +02:00
|
|
|
log.Printf("%s [ %s -> %s ] %s GOOD!!!!", "WE DO!!!", from, to, remoteAddr.String() )
|
2021-07-30 23:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
2021-07-31 13:26:20 +02:00
|
|
|
}
|