|
@@ -1,8 +1,10 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "crypto/tls"
|
|
"flag"
|
|
"flag"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "log"
|
|
"net/smtp"
|
|
"net/smtp"
|
|
|
|
|
|
"github.com/chrj/smtpd"
|
|
"github.com/chrj/smtpd"
|
|
@@ -14,6 +16,9 @@ var (
|
|
welcomeMsg = flag.String("welcome_msg", "", "Welcome message for SMTP session")
|
|
welcomeMsg = flag.String("welcome_msg", "", "Welcome message for SMTP session")
|
|
localHost = flag.String("local_host", "localhost", "Address to listen for incoming SMTP")
|
|
localHost = flag.String("local_host", "localhost", "Address to listen for incoming SMTP")
|
|
localPort = flag.Int("local_port", 25, "Port to listen")
|
|
localPort = flag.Int("local_port", 25, "Port to listen")
|
|
|
|
+ localForceTLS = flag.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
|
|
|
+ localCert = flag.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
|
|
|
+ localKey = flag.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
|
remoteHost = flag.String("remote_host", "smtp.gmail.com", "Outgoing SMTP host")
|
|
remoteHost = flag.String("remote_host", "smtp.gmail.com", "Outgoing SMTP host")
|
|
remotePort = flag.Int("remote_port", 587, "Outgoing SMTP port")
|
|
remotePort = flag.Int("remote_port", 587, "Outgoing SMTP port")
|
|
remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
|
|
remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
|
|
@@ -39,6 +44,18 @@ func main() {
|
|
Hostname: *hostName,
|
|
Hostname: *hostName,
|
|
WelcomeMessage: *welcomeMsg,
|
|
WelcomeMessage: *welcomeMsg,
|
|
Handler: handler,
|
|
Handler: handler,
|
|
|
|
+ ForceTLS: *localForceTLS,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if *localCert != "" && *localKey != "" {
|
|
|
|
+ cert, err := tls.LoadX509KeyPair(*localCert, *localKey)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ server.TLSConfig = &tls.Config {
|
|
|
|
+ Certificates: [] tls.Certificate{cert},
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
server.ListenAndServe(fmt.Sprintf("%s:%d", *localHost, *localPort))
|
|
server.ListenAndServe(fmt.Sprintf("%s:%d", *localHost, *localPort))
|