mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 21:09:39 +00:00
make mail server addr and port dinamically via env
This commit is contained in:
parent
7e8327fd0d
commit
6e0e577916
@ -2,8 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
@ -95,8 +98,28 @@ func main() {
|
|||||||
|
|
||||||
server := smtp.NewServer(backend)
|
server := smtp.NewServer(backend)
|
||||||
|
|
||||||
server.Addr = "localhost:1025"
|
domain, exists := os.LookupEnv("MAIL_SERVER_DOMAIN")
|
||||||
server.Domain = "localhost"
|
if !exists {
|
||||||
|
domain = "localhost"
|
||||||
|
}
|
||||||
|
|
||||||
|
var port int
|
||||||
|
port_str, exists := os.LookupEnv("MAIL_SERVER_PORT")
|
||||||
|
if exists {
|
||||||
|
port, err = strconv.Atoi(port_str)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("env:MAIL_SERVER_PORT is not a number")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
port = 1025
|
||||||
|
}
|
||||||
|
|
||||||
|
if port == 0 {
|
||||||
|
port = 1025
|
||||||
|
}
|
||||||
|
|
||||||
|
server.Addr = fmt.Sprintf("%s:%d", domain, port)
|
||||||
|
server.Domain = domain
|
||||||
server.WriteTimeout = 60 * time.Second
|
server.WriteTimeout = 60 * time.Second
|
||||||
server.ReadTimeout = 60 * time.Second
|
server.ReadTimeout = 60 * time.Second
|
||||||
server.MaxMessageBytes = 1024 * 1024
|
server.MaxMessageBytes = 1024 * 1024
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user