mirror of
https://github.com/Dvorinka/SendMail.git
synced 2026-07-29 10:03:48 +00:00
Merge branch 'main' of https://github.com/Dvorinka/SendMailfe
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"html"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/gomail.v2"
|
||||
)
|
||||
@@ -114,14 +114,14 @@ type FormData struct {
|
||||
|
||||
// rootHandler serves a minimal HTML page with a contact form and JS to submit to /send
|
||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
htmlEsc := html.EscapeString(docsHTMLSnippet)
|
||||
jsEsc := html.EscapeString(docsJSSnippet)
|
||||
page := fmt.Sprintf(`<!DOCTYPE html>
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
htmlEsc := html.EscapeString(docsHTMLSnippet)
|
||||
jsEsc := html.EscapeString(docsJSSnippet)
|
||||
page := fmt.Sprintf(`<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -188,7 +188,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
</div>
|
||||
</body>
|
||||
</html>`, htmlEsc, jsEsc)
|
||||
w.Write([]byte(page))
|
||||
w.Write([]byte(page))
|
||||
}
|
||||
|
||||
type EmailConfig struct {
|
||||
@@ -290,7 +290,8 @@ func enableCors(handler http.HandlerFunc) http.HandlerFunc {
|
||||
|
||||
// sendParamsHandler handles sending email with explicit SMTP parameters via query string.
|
||||
// Example:
|
||||
// GET /[email protected]&pass=secret&server=smtp.example.com&port=465&[email protected]&[email protected]&subject=Hello&message=Hi
|
||||
//
|
||||
// GET /[email protected]&pass=secret&server=smtp.example.com&port=465&[email protected]&[email protected]&subject=Hello&message=Hi
|
||||
func sendParamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
||||
@@ -343,17 +344,14 @@ func sendParamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Email sent successfully"})
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Email sent successfully"})
|
||||
}
|
||||
|
||||
// docsHandler serves a minimal JSON API description.
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/send", enableCors(sendHandler))
|
||||
http.HandleFunc("/send-params", enableCors(sendParamsHandler))
|
||||
http.HandleFunc("/", enableCors(rootHandler))
|
||||
log.Println("Server running on :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
http.HandleFunc("/send", enableCors(sendHandler))
|
||||
log.Println("Server running on :660")
|
||||
log.Fatal(http.ListenAndServe(":660", nil))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user