[GH-ISSUE #148] doc: Where's the documentation? (Simple Example included) #34

Closed
opened 2026-02-26 18:33:01 +03:00 by kerem · 1 comment
Owner

Originally created by @coolaj86 on GitHub (Jan 26, 2024).
Original GitHub issue: https://github.com/decke/smtprelay/issues/148

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.

  • Help
  • Config File / ENVs
  • Build
  • Bcrypt Passwords
  • Simple Example
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

Originally created by @coolaj86 on GitHub (Jan 26, 2024). Original GitHub issue: https://github.com/decke/smtprelay/issues/148 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. - Help - Config File / ENVs - Build - Bcrypt Passwords - Simple Example ```sh 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. ```sh 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. ```sh smtprelay --help ``` ```text 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") ``` ```text 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 ```sh 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
kerem closed this issue 2026-02-26 18:33:01 +03:00
Author
Owner

@decke commented on GitHub (Feb 3, 2025):

Please see #149

<!-- gh-comment-id:2631217039 --> @decke commented on GitHub (Feb 3, 2025): Please see #149
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/smtprelay#34
No description provided.