-
Notifications
You must be signed in to change notification settings - Fork 261
/
mail.go
207 lines (201 loc) · 4.98 KB
/
mail.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package main
import (
"fmt"
"log"
"os"
"github.com/sendgrid/sendgrid-go"
)
// CreateabatchID : Create a batch ID
// POST /mail/batch
func CreateabatchID() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/mail/batch", 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)
}
}
// ValidatebatchID : Validate batch ID
// GET /mail/batch/{batch_id}
func ValidatebatchID() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/mail/batch/{batch_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)
}
}
// v3MailSend : v3 Mail Send
// POST /mail/send
// This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-go/blob/HEAD/helpers/mail/README.md).
func v3MailSend() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "https://api.sendgrid.com"
request := sendgrid.GetRequest(apiKey, "/v3/mail/send", host)
request.Method = "POST"
request.Body = []byte(` {
"asm": {
"group_id": 1,
"groups_to_display": [
1,
2,
3
]
},
"attachments": [
{
"content": "[BASE64 encoded content block here]",
"content_id": "ii_139db99fdb5c3704",
"disposition": "inline",
"filename": "file1.jpg",
"name": "file1",
"type": "jpg"
}
],
"batch_id": "[YOUR BATCH ID GOES HERE]",
"categories": [
"category1",
"category2"
],
"content": [
{
"type": "text/html",
"value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
}
],
"custom_args": {
"New Argument 1": "New Value 1",
"activationAttempt": "1",
"customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
},
"from": {
"email": "[email protected]",
"name": "Sam Smith"
},
"headers": {},
"ip_pool_name": "[YOUR POOL NAME GOES HERE]",
"mail_settings": {
"bcc": {
"email": "[email protected]",
"enable": true
},
"bypass_list_management": {
"enable": true
},
"footer": {
"enable": true,
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
"text": "Thanks,/n The Twilio SendGrid Team"
},
"sandbox_mode": {
"enable": false
},
"spam_check": {
"enable": true,
"post_to_url": "http://example.com/compliance",
"threshold": 3
}
},
"personalizations": [
{
"bcc": [
{
"email": "[email protected]",
"name": "Sam Doe"
}
],
"cc": [
{
"email": "[email protected]",
"name": "Jane Doe"
}
],
"custom_args": {
"New Argument 1": "New Value 1",
"activationAttempt": "1",
"customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
},
"headers": {
"X-Accept-Language": "en",
"X-Mailer": "MyApp"
},
"send_at": 1409348513,
"subject": "Hello, World!",
"substitutions": {
"id": "substitutions",
"type": "object"
},
"from": {
"email": "[email protected]",
"name": "Bob Doe"
},
"to": [
{
"email": "[email protected]",
"name": "John Doe"
}
]
}
],
"reply_to": {
"email": "[email protected]",
"name": "Sam Smith"
},
"sections": {
"section": {
":sectionName1": "section 1 text",
":sectionName2": "section 2 text"
}
},
"send_at": 1409348513,
"subject": "Hello, World!",
"template_id": "[YOUR TEMPLATE ID GOES HERE]",
"tracking_settings": {
"click_tracking": {
"enable": true,
"enable_text": true
},
"ganalytics": {
"enable": true,
"utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
"utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
"utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
"utm_name": "[NAME OF YOUR CAMPAIGN]",
"utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
},
"open_tracking": {
"enable": true,
"substitution_tag": "%opentrack"
},
"subscription_tracking": {
"enable": true,
"html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
"substitution_tag": "<%click here%>",
"text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
}
}
}`)
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
}