diff --git a/main.go b/main.go index 3870d16..de3614e 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "html" "log" "net/http" + "os" "strconv" "strings" @@ -208,6 +209,7 @@ var domainMap = map[string]EmailConfig{ } func sendHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("[send] INCOMING %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr) if r.Method != http.MethodPost { http.Error(w, "POST only", http.StatusMethodNotAllowed) return @@ -301,6 +303,7 @@ func enableCors(handler http.HandlerFunc) http.HandlerFunc { // // GET /send-params?email=user@example.com&pass=secret&server=smtp.example.com&port=465&to=dest@example.com&from=user@example.com&subject=Hello&message=Hi func sendParamsHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("[send-params] INCOMING %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr) if r.Method != http.MethodGet { http.Error(w, "GET only", http.StatusMethodNotAllowed) return @@ -363,6 +366,16 @@ func main() { http.HandleFunc("/", enableCors(rootHandler)) http.HandleFunc("/send", enableCors(sendHandler)) http.HandleFunc("/send-params", enableCors(sendParamsHandler)) - log.Println("Server running on localhost:660") - log.Fatal(http.ListenAndServe("localhost:660", nil)) + + host := os.Getenv("HOST") + if host == "" { + host = "localhost" + } + port := os.Getenv("PORT") + if port == "" { + port = "660" + } + addr := host + ":" + port + log.Println("Server running on " + addr) + log.Fatal(http.ListenAndServe(addr, nil)) }