forked from drew/smtprelay
Compare commits
80 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6857874c88 | ||
|
|
9051ffddf7 | ||
|
|
7e318cbcbc | ||
|
|
5d625efa45 | ||
|
|
df0580c8e6 | ||
|
|
3697382181 | ||
|
|
76ecb52831 | ||
|
|
c7651c36a3 | ||
|
|
b4cef48825 | ||
|
|
620355677d | ||
|
|
ab24fb4427 | ||
|
|
71fcfb8f0d | ||
|
|
68cc6954d0 | ||
|
|
b0001c4842 | ||
|
|
330ecc9603 | ||
|
|
eb670615d2 | ||
|
|
ab5d3e3aa7 | ||
|
|
7b962e06e5 | ||
|
|
3e49c58b95 | ||
|
|
f7df20258e | ||
|
|
b2544f8da8 | ||
|
|
a2e2ab7592 | ||
|
|
755b8b2d8e | ||
|
|
a632f62b45 | ||
|
|
10100b140d | ||
|
|
0f95efa66f | ||
|
|
34d61707ab | ||
|
|
e032832820 | ||
|
|
2affd381ba | ||
|
|
d86165d5e4 | ||
|
|
e611751852 | ||
|
|
c7710d4437 | ||
|
|
204d2f20e9 | ||
|
|
73349c6f4d | ||
|
|
0f1caae1ff | ||
|
|
da368f5277 | ||
|
|
1f71df1e03 | ||
|
|
cc064e497e | ||
|
|
b4eac9a7d2 | ||
|
|
6782c7896e | ||
|
|
b652918f30 | ||
|
|
bf75b0474e | ||
|
|
e8dc491e0f | ||
|
|
18f3d9e379 | ||
|
|
088fa4cfd8 | ||
|
|
56d427e8a7 | ||
|
|
42d111695d | ||
|
|
36b9b92a9f | ||
|
|
41a97fe44f | ||
|
|
02044f647b | ||
|
|
813bd9ebe7 | ||
|
|
ee8a5dd989 | ||
|
|
6602836166 | ||
|
|
cdc0fe931b | ||
|
|
e5f27e02e5 | ||
|
|
dffe0bb5bb | ||
|
|
20ad1e84f9 | ||
|
|
db1238bf2d | ||
|
|
d9167eece5 | ||
|
|
e98a1c6f25 | ||
|
|
f0aefc194d | ||
|
|
bfd156e5f3 | ||
|
|
682feef610 | ||
|
|
eea3c4edaa | ||
|
|
cf25c2d0a0 | ||
|
|
774651b0f6 | ||
|
|
5cd3729b1f | ||
|
|
5b38a30349 | ||
|
|
d7585bec9b | ||
|
|
c8f62e42c8 | ||
|
|
00df491340 | ||
|
|
1bf205e7d8 | ||
|
|
c83544bd90 | ||
|
|
e3ba45ede2 | ||
|
|
f69d1f0114 | ||
|
|
e9a2b9ad5a | ||
|
|
7e3dbd515d | ||
|
|
8cc31a918b | ||
|
|
26477177fe | ||
|
|
44560c9a0c |
18
.github/workflows/go.yml
vendored
18
.github/workflows/go.yml
vendored
@@ -6,19 +6,13 @@ jobs:
|
|||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Go 1.18
|
- uses: actions/setup-go@v4
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
with:
|
||||||
go-version: 1.18
|
go-version: 'stable'
|
||||||
id: go
|
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Get dependencies
|
|
||||||
run: |
|
|
||||||
go get -v -t -d ./...
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v .
|
run: go build -v .
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v .
|
||||||
|
|||||||
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@@ -20,11 +20,11 @@ jobs:
|
|||||||
- name: Set BUILD_TIME env
|
- name: Set BUILD_TIME env
|
||||||
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
|
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
|
||||||
|
|
||||||
- uses: wangyoucao577/go-release-action@v1.28
|
- uses: wangyoucao577/go-release-action@v1
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
goos: ${{ matrix.goos }}
|
goos: ${{ matrix.goos }}
|
||||||
goarch: ${{ matrix.goarch }}
|
goarch: ${{ matrix.goarch }}
|
||||||
goversion: 1.18
|
goversion: "1.20"
|
||||||
extra_files: LICENSE README.md smtprelay.ini
|
extra_files: LICENSE README.md smtprelay.ini
|
||||||
ldflags: -s -w -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}"
|
ldflags: -s -w -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ device which produces mail.
|
|||||||
|
|
||||||
## Main features
|
## Main features
|
||||||
|
|
||||||
|
* Simple configuration with ini file .env file or environment variables
|
||||||
* Supports SMTPS/TLS (465), STARTTLS (587) and unencrypted SMTP (25)
|
* Supports SMTPS/TLS (465), STARTTLS (587) and unencrypted SMTP (25)
|
||||||
* Checks for sender, receiver, client IP
|
* Checks for sender, receiver, client IP
|
||||||
* Authentication support with file (LOGIN, PLAIN)
|
* Authentication support with file (LOGIN, PLAIN)
|
||||||
|
|||||||
123
config.go
123
config.go
@@ -1,15 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/peterbourgon/ff/v3"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/vharitonsky/iniflags"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -18,36 +21,44 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logFile = flag.String("logfile", "", "Path to logfile")
|
flagset = flag.NewFlagSet("smtprelay", flag.ContinueOnError)
|
||||||
logFormat = flag.String("log_format", "default", "Log output format")
|
|
||||||
logLevel = flag.String("log_level", "info", "Minimum log level to output")
|
// config flags
|
||||||
hostName = flag.String("hostname", "localhost.localdomain", "Server hostname")
|
logFile = flagset.String("logfile", "", "Path to logfile")
|
||||||
welcomeMsg = flag.String("welcome_msg", "", "Welcome message for SMTP session")
|
logFormat = flagset.String("log_format", "default", "Log output format")
|
||||||
listenStr = flag.String("listen", "127.0.0.1:25 [::1]:25", "Address and port to listen for incoming SMTP")
|
logLevel = flagset.String("log_level", "info", "Minimum log level to output")
|
||||||
|
hostName = flagset.String("hostname", "localhost.localdomain", "Server hostname")
|
||||||
|
welcomeMsg = flagset.String("welcome_msg", "", "Welcome message for SMTP session")
|
||||||
|
listenStr = flagset.String("listen", "127.0.0.1:25 [::1]:25", "Address and port to listen for incoming SMTP")
|
||||||
|
localCert = flagset.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
||||||
|
localKey = flagset.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
||||||
|
localForceTLS = flagset.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
||||||
|
readTimeoutStr = flagset.String("read_timeout", "60s", "Socket timeout for read operations")
|
||||||
|
writeTimeoutStr = flagset.String("write_timeout", "60s", "Socket timeout for write operations")
|
||||||
|
dataTimeoutStr = flagset.String("data_timeout", "5m", "Socket timeout for DATA command")
|
||||||
|
maxConnections = flagset.Int("max_connections", 100, "Max concurrent connections, use -1 to disable")
|
||||||
|
maxMessageSize = flagset.Int("max_message_size", 10240000, "Max message size in bytes")
|
||||||
|
maxRecipients = flagset.Int("max_recipients", 100, "Max RCPT TO calls for each envelope")
|
||||||
|
allowedNetsStr = flagset.String("allowed_nets", "127.0.0.0/8 ::1/128", "Networks allowed to send mails")
|
||||||
|
allowedSenderStr = flagset.String("allowed_sender", "", "Regular expression for valid FROM EMail addresses")
|
||||||
|
allowedRecipStr = flagset.String("allowed_recipients", "", "Regular expression for valid TO EMail addresses")
|
||||||
|
allowedUsers = flagset.String("allowed_users", "", "Path to file with valid users/passwords")
|
||||||
|
command = flagset.String("command", "", "Path to pipe command")
|
||||||
|
remotesStr = flagset.String("remotes", "", "Outgoing SMTP servers")
|
||||||
|
|
||||||
|
// additional flags
|
||||||
|
_ = flagset.String("config", "", "Path to config file (ini format)")
|
||||||
|
versionInfo = flagset.Bool("version", false, "Show version information")
|
||||||
|
|
||||||
|
// internal
|
||||||
listenAddrs = []protoAddr{}
|
listenAddrs = []protoAddr{}
|
||||||
localCert = flag.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
|
||||||
localKey = flag.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
|
||||||
localForceTLS = flag.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
|
||||||
readTimeoutStr = flag.String("read_timeout", "60s", "Socket timeout for read operations")
|
|
||||||
readTimeout time.Duration
|
readTimeout time.Duration
|
||||||
writeTimeoutStr = flag.String("write_timeout", "60s", "Socket timeout for write operations")
|
|
||||||
writeTimeout time.Duration
|
writeTimeout time.Duration
|
||||||
dataTimeoutStr = flag.String("data_timeout", "5m", "Socket timeout for DATA command")
|
|
||||||
dataTimeout time.Duration
|
dataTimeout time.Duration
|
||||||
maxConnections = flag.Int("max_connections", 100, "Max concurrent connections, use -1 to disable")
|
|
||||||
maxMessageSize = flag.Int("max_message_size", 10240000, "Max message size in bytes")
|
|
||||||
maxRecipients = flag.Int("max_recipients", 100, "Max RCPT TO calls for each envelope")
|
|
||||||
allowedNetsStr = flag.String("allowed_nets", "127.0.0.0/8 ::1/128", "Networks allowed to send mails")
|
|
||||||
allowedNets = []*net.IPNet{}
|
allowedNets = []*net.IPNet{}
|
||||||
allowedSenderStr = flag.String("allowed_sender", "", "Regular expression for valid FROM EMail addresses")
|
|
||||||
allowedSender *regexp.Regexp
|
allowedSender *regexp.Regexp
|
||||||
allowedRecipStr = flag.String("allowed_recipients", "", "Regular expression for valid TO EMail addresses")
|
|
||||||
allowedRecipients *regexp.Regexp
|
allowedRecipients *regexp.Regexp
|
||||||
allowedUsers = flag.String("allowed_users", "", "Path to file with valid users/passwords")
|
|
||||||
command = flag.String("command", "", "Path to pipe command")
|
|
||||||
remotesStr = flag.String("remotes", "", "Outgoing SMTP servers")
|
|
||||||
remotes = []*Remote{}
|
remotes = []*Remote{}
|
||||||
versionInfo = flag.Bool("version", false, "Show version information")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func localAuthRequired() bool {
|
func localAuthRequired() bool {
|
||||||
@@ -183,11 +194,36 @@ func setupTimeouts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConfigLoad() {
|
func ConfigLoad() {
|
||||||
iniflags.Parse()
|
// use .env file if it exists
|
||||||
|
if _, err := os.Stat(".env"); err == nil {
|
||||||
|
if err := ff.Parse(flagset, os.Args[1:],
|
||||||
|
ff.WithEnvVarPrefix("smtprelay"),
|
||||||
|
ff.WithConfigFile(".env"),
|
||||||
|
ff.WithConfigFileParser(ff.EnvParser),
|
||||||
|
); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// use env variables and smtprelay.ini file
|
||||||
|
if err := ff.Parse(flagset, os.Args[1:],
|
||||||
|
ff.WithEnvVarPrefix("smtprelay"),
|
||||||
|
ff.WithConfigFileFlag("config"),
|
||||||
|
ff.WithConfigFileParser(IniParser),
|
||||||
|
); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set up logging as soon as possible
|
// Set up logging as soon as possible
|
||||||
setupLogger()
|
setupLogger()
|
||||||
|
|
||||||
|
if *versionInfo {
|
||||||
|
fmt.Printf("smtprelay/%s (%s)\n", appVersion, buildTime)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if *remotesStr == "" && *command == "" {
|
if *remotesStr == "" && *command == "" {
|
||||||
log.Warn("no remotes or command set; mail will not be forwarded!")
|
log.Warn("no remotes or command set; mail will not be forwarded!")
|
||||||
}
|
}
|
||||||
@@ -198,3 +234,42 @@ func ConfigLoad() {
|
|||||||
setupListeners()
|
setupListeners()
|
||||||
setupTimeouts()
|
setupTimeouts()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IniParser is a parser for config files in classic key/value style format. Each
|
||||||
|
// line is tokenized as a single key/value pair. The first "=" delimited
|
||||||
|
// token in the line is interpreted as the flag name, and all remaining tokens
|
||||||
|
// are interpreted as the value. Any leading hyphens on the flag name are
|
||||||
|
// ignored.
|
||||||
|
func IniParser(r io.Reader, set func(name, value string) error) error {
|
||||||
|
s := bufio.NewScanner(r)
|
||||||
|
for s.Scan() {
|
||||||
|
line := strings.TrimSpace(s.Text())
|
||||||
|
if line == "" {
|
||||||
|
continue // skip empties
|
||||||
|
}
|
||||||
|
|
||||||
|
if line[0] == '#' || line[0] == ';' {
|
||||||
|
continue // skip comments
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
name string
|
||||||
|
value string
|
||||||
|
index = strings.IndexRune(line, '=')
|
||||||
|
)
|
||||||
|
if index < 0 {
|
||||||
|
name, value = line, "true" // boolean option
|
||||||
|
} else {
|
||||||
|
name, value = strings.TrimSpace(line[:index]), strings.Trim(strings.TrimSpace(line[index+1:]), "\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
if i := strings.Index(value, " #"); i >= 0 {
|
||||||
|
value = strings.TrimSpace(value[:i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := set(name, value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
16
go.mod
16
go.mod
@@ -3,17 +3,19 @@ module github.com/decke/smtprelay
|
|||||||
require (
|
require (
|
||||||
github.com/chrj/smtpd v0.3.1
|
github.com/chrj/smtpd v0.3.1
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/peterbourgon/ff/v3 v3.3.2
|
||||||
github.com/stretchr/testify v1.7.1
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
|
github.com/stretchr/testify v1.8.4
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
|
golang.org/x/crypto v0.10.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
|
golang.org/x/sys v0.9.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|||||||
41
go.sum
41
go.sum
@@ -1,26 +1,39 @@
|
|||||||
github.com/chrj/smtpd v0.3.1 h1:kogHFkbFdKaoH3bgZkqNC9uVtKYOFfM3uV3rroBdooE=
|
github.com/chrj/smtpd v0.3.1 h1:kogHFkbFdKaoH3bgZkqNC9uVtKYOFfM3uV3rroBdooE=
|
||||||
github.com/chrj/smtpd v0.3.1/go.mod h1:JtABvV/LzvLmEIzy0NyDnrfMGOMd8wy5frAokwf6J9Q=
|
github.com/chrj/smtpd v0.3.1/go.mod h1:JtABvV/LzvLmEIzy0NyDnrfMGOMd8wy5frAokwf6J9Q=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/peterbourgon/ff/v3 v3.3.2 h1:2J07/5/36kd9HYVt42Zve0xCeQ+LLRIvoKrt6sAZXJ4=
|
||||||
|
github.com/peterbourgon/ff/v3 v3.3.2/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg=
|
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
|
||||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
|
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
|
|
||||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -177,7 +177,16 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
|||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
|
|
||||||
cmd := exec.Command(*command)
|
environ := os.Environ()
|
||||||
|
environ = append(environ, fmt.Sprintf("%s=%s", "SMTPRELAY_FROM", env.Sender))
|
||||||
|
environ = append(environ, fmt.Sprintf("%s=%s", "SMTPRELAY_TO", env.Recipients))
|
||||||
|
environ = append(environ, fmt.Sprintf("%s=%s", "SMTPRELAY_PEER", peerIP))
|
||||||
|
|
||||||
|
cmd := exec.Cmd{
|
||||||
|
Env: environ,
|
||||||
|
Path: *command,
|
||||||
|
}
|
||||||
|
|
||||||
cmd.Stdin = bytes.NewReader(env.Data)
|
cmd.Stdin = bytes.NewReader(env.Data)
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
@@ -282,11 +291,6 @@ func getTLSConfig() *tls.Config {
|
|||||||
func main() {
|
func main() {
|
||||||
ConfigLoad()
|
ConfigLoad()
|
||||||
|
|
||||||
if *versionInfo {
|
|
||||||
fmt.Printf("smtprelay/%s (%s)\n", appVersion, buildTime)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithField("version", appVersion).
|
log.WithField("version", appVersion).
|
||||||
Debug("starting smtprelay")
|
Debug("starting smtprelay")
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ type Remote struct {
|
|||||||
// Supported Params:
|
// Supported Params:
|
||||||
// - skipVerify: can be "true" or empty to prevent ssl verification of remote server's certificate.
|
// - skipVerify: can be "true" or empty to prevent ssl verification of remote server's certificate.
|
||||||
// - auth: can be "login" to trigger "LOGIN" auth instead of "PLAIN" auth
|
// - auth: can be "login" to trigger "LOGIN" auth instead of "PLAIN" auth
|
||||||
//
|
|
||||||
func ParseRemote(remoteURL string) (*Remote, error) {
|
func ParseRemote(remoteURL string) (*Remote, error) {
|
||||||
u, err := url.Parse(remoteURL)
|
u, err := url.Parse(remoteURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
; smtprelay configuration
|
; smtprelay configuration
|
||||||
|
;
|
||||||
|
; All config parameters can also be provided as environment
|
||||||
|
; variables in uppercase and the prefix "SMTPRELAY_".
|
||||||
|
; (eg. SMTPRELAY_LOGFILE, SMTPRELAY_LOG_FORMAT)
|
||||||
|
|
||||||
; Logfile (blank/default is stderr)
|
; Logfile (blank/default is stderr)
|
||||||
;logfile =
|
;logfile =
|
||||||
|
|
||||||
; Log format: default, plain (no timestamp), json
|
; Log format: default, plain (no timestamp), json
|
||||||
;log_format = "default"
|
;log_format = default
|
||||||
|
|
||||||
; Log level: panic, fatal, error, warn, info, debug, trace
|
; Log level: panic, fatal, error, warn, info, debug, trace
|
||||||
;log_level = "info"
|
;log_level = info
|
||||||
|
|
||||||
; Hostname for this SMTP server
|
; Hostname for this SMTP server
|
||||||
;hostname = "localhost.localdomain"
|
;hostname = localhost.localdomain
|
||||||
|
|
||||||
; Welcome message for clients
|
; Welcome message for clients
|
||||||
;welcome_msg = "<hostname> ESMTP ready."
|
;welcome_msg = <hostname> ESMTP ready.
|
||||||
|
|
||||||
; Listen on the following addresses for incoming
|
; Listen on the following addresses for incoming
|
||||||
; unencrypted connections.
|
; unencrypted connections.
|
||||||
|
|||||||
Reference in New Issue
Block a user