mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-26 06:32:28 -07:00
Add support for TLS and STARTTLS
This commit is contained in:
17
main.go
17
main.go
@@ -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))
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
;hostname = "localhost.localdomain"
|
;hostname = "localhost.localdomain"
|
||||||
;welcome_msg = "<hostname> ESMTP ready."
|
;welcome_msg = "<hostname> ESMTP ready."
|
||||||
|
|
||||||
;local_host = 127.0.0.1
|
;local_host = localhost
|
||||||
;local_port = 25
|
;local_port = 25
|
||||||
|
;local_cert =
|
||||||
|
;local_key =
|
||||||
|
;local_forcetls = false
|
||||||
|
|
||||||
;remote_host = smtp.gmail.com
|
;remote_host = smtp.gmail.com
|
||||||
;remote_port = 587
|
;remote_port = 587
|
||||||
|
|||||||
Reference in New Issue
Block a user