mirror of
https://github.com/Dvorinka/SendMail.git
synced 2026-07-29 01:53:47 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
module mail
|
||||||
|
|
||||||
|
go 1.24.3
|
||||||
|
|
||||||
|
require gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||||
|
|
||||||
|
require gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||||
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
|
||||||
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/gomail.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FormData struct {
|
||||||
|
Domain string `json:"domain"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Subject string `json:"subject"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmailConfig struct {
|
||||||
|
Email string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
|
var domainMap = map[string]EmailConfig{
|
||||||
|
"tdvorak.dev": {"[email protected]", "%8s3Yad*!b3*t"},
|
||||||
|
"vbly.org": {"[email protected]", "!N0^e0Q9k*mV"},
|
||||||
|
"sportcreative.eu": {"[email protected]", "@dN$TZPgG5!"},
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "POST only", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data FormData
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||||
|
http.Error(w, "Invalid JSON", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Domain = strings.ToLower(strings.TrimSpace(data.Domain))
|
||||||
|
config, ok := domainMap[data.Domain]
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "Unknown domain", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m := gomail.NewMessage()
|
||||||
|
m.SetHeader("From", config.Email)
|
||||||
|
m.SetHeader("To", config.Email) // you can change this to forward to another inbox
|
||||||
|
m.SetHeader("Subject", data.Subject)
|
||||||
|
m.SetBody("text/plain", "Name: "+data.Name+"\nEmail: "+data.Email+"\n\n"+data.Message)
|
||||||
|
|
||||||
|
d := gomail.NewDialer("smtp.purelymail.com", 465, config.Email, config.Password)
|
||||||
|
d.SSL = true // Purelymail recommends SSL on port 465
|
||||||
|
|
||||||
|
if err := d.DialAndSend(m); err != nil {
|
||||||
|
log.Println("Email send error:", err)
|
||||||
|
http.Error(w, "Failed to send email", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write([]byte("Email sent successfully"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/send", sendHandler)
|
||||||
|
log.Println("Server running on :8080")
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user