-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
59 lines (39 loc) · 1.03 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/smtp"
"github.com/gorilla/mux"
)
func main() {
fmt.Println("Server started...")
fmt.Println(" * Running on http://127.0.0.1:8080/")
fmt.Println(" * IP: localhost")
fmt.Println(" * Port: 8080")
r := mux.NewRouter()
r.HandleFunc("/sendEmail", sendEmail).Queries("email", "{email}", "msg", "{msg}").Methods("GET")
path := "model"
r.PathPrefix("/").Handler(http.FileServer(http.Dir(path)))
http.ListenAndServe(":8080", r)
fmt.Println("Server End")
}
func sendEmail(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
from := "[email protected]"
pass := "kqu3-b@vFu_/P4W7"
to := params["email"]
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: emergency\n\n" +
params["msg"]
err := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err != nil {
log.Printf("smtp error: %s", err)
return
}
json.NewEncoder(w).Encode("Message Sent!")
}