From 7b4a51d62c3228c474dd5e886a57f619129b9e67 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Sat, 8 Dec 2018 21:19:56 +0000 Subject: [PATCH] Initial commit --- go.mod | 6 ++++++ go.sum | 5 +++++ main.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ smtp-proxy.ini | 12 ++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 smtp-proxy.ini diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8bc00fc --- /dev/null +++ b/go.mod @@ -0,0 +1,6 @@ +module code.bluelife.at/decke/smtp-proxy + +require ( + github.com/chrj/smtpd v0.1.1 + github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4be459f --- /dev/null +++ b/go.sum @@ -0,0 +1,5 @@ +github.com/chrj/smtpd v0.1.1 h1:Jk9ZimOh4njDpMbDLPmdQX+x9AUYGrfE68EyjuQDPjk= +github.com/chrj/smtpd v0.1.1/go.mod h1:jt4ydELuZmqhn9hn3YpEPV1dY00aOB+Q1nWXnBDFKeY= +github.com/eaigner/dkim v0.0.0-20150301120808-6fe4a7ee9cfb/go.mod h1:FSCIHbrqk7D01Mj8y/jW+NS1uoCerr+ad+IckTHTFf4= +github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg= +github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI= diff --git a/main.go b/main.go new file mode 100644 index 0000000..eeef5d7 --- /dev/null +++ b/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "flag" + "fmt" + "net/smtp" + + "github.com/chrj/smtpd" + "github.com/vharitonsky/iniflags" +) + +var ( + hostName = flag.String("hostname", "localhost.localdomain", "Server hostname") + welcomeMsg = flag.String("welcome_msg", "", "Welcome message for SMTP session") + localHost = flag.String("local_host", "localhost", "Address to listen for incoming SMTP") + localPort = flag.Int("local_port", 25, "Port to listen") + remoteHost = flag.String("remote_host", "smtp.gmail.com", "Outgoing SMTP host") + remotePort = flag.Int("remote_port", 587, "Outgoing SMTP port") + remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server") + remotePass = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server") +) + +func handler(peer smtpd.Peer, env smtpd.Envelope) error { + + return smtp.SendMail( + fmt.Sprintf("%s:%d", *remoteHost, *remotePort), + smtp.PlainAuth("", *remoteUser, *remotePass, *remoteHost), + env.Sender, + env.Recipients, + env.Data, + ) +} + +func main() { + + iniflags.Parse() + + server := &smtpd.Server{ + Hostname: *hostName, + WelcomeMessage: *welcomeMsg, + Handler: handler, + } + + server.ListenAndServe(fmt.Sprintf("%s:%d", *localHost, *localPort)) +} diff --git a/smtp-proxy.ini b/smtp-proxy.ini new file mode 100644 index 0000000..2256f11 --- /dev/null +++ b/smtp-proxy.ini @@ -0,0 +1,12 @@ +; smtp-proxy configuration + +;hostname = "localhost.localdomain" +;welcome_msg = " ESMTP ready." + +;local_host = 127.0.0.1 +;local_port = 25 + +;remote_host = smtp.gmail.com +;remote_port = 587 +;remote_user = +;remote_pass =