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"
|
"html"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/gomail.v2"
|
"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
|
// rootHandler serves a minimal HTML page with a contact form and JS to submit to /send
|
||||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
htmlEsc := html.EscapeString(docsHTMLSnippet)
|
htmlEsc := html.EscapeString(docsHTMLSnippet)
|
||||||
jsEsc := html.EscapeString(docsJSSnippet)
|
jsEsc := html.EscapeString(docsJSSnippet)
|
||||||
page := fmt.Sprintf(`<!DOCTYPE html>
|
page := fmt.Sprintf(`<!DOCTYPE html>
|
||||||
<html lang="cs">
|
<html lang="cs">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
@@ -188,7 +188,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>`, htmlEsc, jsEsc)
|
</html>`, htmlEsc, jsEsc)
|
||||||
w.Write([]byte(page))
|
w.Write([]byte(page))
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailConfig struct {
|
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.
|
// sendParamsHandler handles sending email with explicit SMTP parameters via query string.
|
||||||
// Example:
|
// 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) {
|
func sendParamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
http.Error(w, "GET only", http.StatusMethodNotAllowed)
|
||||||
@@ -343,17 +344,14 @@ func sendParamsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Email sent successfully"})
|
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Email sent successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// docsHandler serves a minimal JSON API description.
|
// docsHandler serves a minimal JSON API description.
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/send", enableCors(sendHandler))
|
http.HandleFunc("/send", enableCors(sendHandler))
|
||||||
http.HandleFunc("/send-params", enableCors(sendParamsHandler))
|
log.Println("Server running on :660")
|
||||||
http.HandleFunc("/", enableCors(rootHandler))
|
log.Fatal(http.ListenAndServe(":660", nil))
|
||||||
log.Println("Server running on :8080")
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user