-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfunction.go
42 lines (35 loc) · 946 Bytes
/
cloudfunction.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
// Package p contains an HTTP Cloud Function.
package p
import (
"encoding/json"
"fmt"
"net/smtp"
"log"
"net/http"
)
// HelloWorld prints the JSON encoded "message" field in the body
// of the request or "Hello, World!" if there isn't one.
func HelloWorld(w http.ResponseWriter, r *http.Request) {
var d struct {
Message string `json:"message"`
}
if err := json.NewDecoder(r.Body).Decode(&d); err != nil {
fmt.Fprint(w, "test success!")
return
}
fmt.Fprint(w, "test success2!")
from := "richardred.q@gmail.com"
pass := "nkiteujirbmhqazn"
to := "yoyobrains0@gmail.com"
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: Hello there\n\n" +
"yeet12345678"
err2 := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err2 != nil {
log.Printf("smtp error: %s", err2)
return
}
}