decke / smtprelay

Simple Golang SMTP relay/proxy server
MIT License
459 stars 110 forks source link

doc: Where's the documentation? (Simple Example included) #148

Open coolaj86 opened 9 months ago

coolaj86 commented 9 months ago

Since this doesn't have docs on godoc, or usage in the README, I'm just adding some here while I figure out how to use this.

smtprelay -config ~/.config/smtprelay/smtprelay.ini

Test with curl

This looks more complicated than it is because both styles of header need to be specified (in the message file and the mime headers). It may work with just the one in some curl versions. It also requires listening on port 465.

my_smtprelay_host=smtp.example.com
my_smtprelay_auth='my-user:my-pass'

my_from="rob-the-robot@example.com"
my_to="alice@example.net"
my_subject='Hello, World!'
my_ts="$(date '+%F %H:%M:%S')"
my_text="It's ${my_ts}. Do you know where your emails are?"

my_file="$(mktemp)"
printf 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\n' \
        "${my_from}" \
        "${my_to}" \
        "${my_subject}" \
        "${my_text}" \
        > "${my_file}"

# requires tls on 465
curl -v --url "smtps://${my_smtprelay_host}" \
  --ssl-reqd \
  --user "${my_smtprelay_auth}" \
  --mail-from "${my_from}" \
  --mail-rcpt "${my_to}" \
  --upload-file "${my_file}"

Help

Any unrecognized flag, such as --help, will show the help.

smtprelay --help
Usage of smtprelay:
  -allowed_nets string
        Networks allowed to send mails (default "127.0.0.0/8 ::1/128")
  -allowed_recipients string
        Regular expression for valid TO EMail addresses
  -allowed_sender string
        Regular expression for valid FROM EMail addresses
  -allowed_users string
        Path to file with valid users/passwords
  -command string
        Path to pipe command
  -config string
        Path to config file (ini format)
  -data_timeout string
        Socket timeout for DATA command (default "5m")
  -hostname string
        Server hostname (default "localhost.localdomain")
  -listen string
        Address and port to listen for incoming SMTP (default "127.0.0.1:25 [::1]:25")
  -local_cert string
        SSL certificate for STARTTLS/TLS
  -local_forcetls
        Force STARTTLS (needs local_cert and local_key)
  -local_key string
        SSL private key for STARTTLS/TLS
  -log_format string
        Log output format (default "default")
  -log_level string
        Minimum log level to output (default "info")
  -logfile string
        Path to logfile
  -max_connections int
        Max concurrent connections, use -1 to disable (default 100)
  -max_message_size int
        Max message size in bytes (default 10240000)
  -max_recipients int
        Max RCPT TO calls for each envelope (default 100)
  -read_timeout string
        Socket timeout for read operations (default "60s")
  -remotes string
        Outgoing SMTP servers
  -strict_sender
        Use only SMTP servers with Sender matches to From
  -version
        Show version information
  -welcome_msg string
        Welcome message for SMTP session
  -write_timeout string
        Socket timeout for write operations (default "60s")
error: error parsing commandline arguments: flag provided but not defined: -help

Config File / ENVs

This is the example config file: https://github.com/decke/smtprelay/blob/master/smtprelay.ini

It can be converted to a the more webdev-friendly ENV format simply by using SMTPRELAY_* with the config options in upper case.

Build

git clone 

pushd ./

go build -o ./smtprelay ./

Bcrypt Passwords

There's a bcrypt hasher in ./cmd/hasher.go

Simple Example

Moved to https://github.com/decke/smtprelay/issues/149