-
Notifications
You must be signed in to change notification settings - Fork 260
/
emailactivity.go
93 lines (83 loc) · 2.26 KB
/
emailactivity.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"log"
"net/url"
"os"
"github.com/sendgrid/sendgrid-go/v4"
)
// GetMessages : Filter all messages
// GET /messages
func GetMessages() {
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/messages", host)
request.Method = "GET"
filterKey := "to_email"
filterOperator := url.QueryEscape("=")
filterValue := "testing@sendgrid.net"
filterValue = url.QueryEscape(fmt.Sprintf("\"%s\"", filterValue))
queryParams := make(map[string]string)
queryParams["query"] = fmt.Sprintf("%s%s%s", filterKey, filterOperator, filterValue)
queryParams["limit"] = "1"
request.QueryParams = queryParams
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
// GetMessagesByID : Filter messages by message ID
// GET /messages/{msg_id}
func GetMessagesByID() {
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/messages/{msg_id}", host)
request.Method = "GET"
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
// RequestCSV : Request a CSV
// POST /messages/download
func RequestCSV() {
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/messages/download", host)
request.Method = "POST"
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
// DownloadCSV : Download CSV
// GET /messages/download/{download_uuid}
func DownloadCSV() {
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/messages/download/{download_uuid}", host)
request.Method = "GET"
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
func main() {
// add your function calls here
}