forked from drew/smtprelay
Initial commit
This commit is contained in:
45
main.go
Normal file
45
main.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user