Initial commit

This commit is contained in:
Bernhard Froehlich
2018-12-08 21:19:56 +00:00
parent c707438ae8
commit 7b4a51d62c
4 changed files with 68 additions and 0 deletions

6
go.mod Normal file
View File

@@ -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
)

5
go.sum Normal file
View File

@@ -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=

45
main.go Normal file
View File

@@ -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))
}

12
smtp-proxy.ini Normal file
View File

@@ -0,0 +1,12 @@
; smtp-proxy configuration
;hostname = "localhost.localdomain"
;welcome_msg = "<hostname> ESMTP ready."
;local_host = 127.0.0.1
;local_port = 25
;remote_host = smtp.gmail.com
;remote_port = 587
;remote_user =
;remote_pass =