-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailchimp.go
42 lines (35 loc) · 963 Bytes
/
mailchimp.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 main
import (
"time"
"github.com/hanzoai/gochimp3"
)
func createAndSendCampaign(apiKey string, templateId uint, listId string) error {
client := gochimp3.New(apiKey)
client.Timeout = 60 * time.Second
createCampaignRequest := gochimp3.CampaignCreationRequest{
Type: gochimp3.CAMPAIGN_TYPE_REGULAR,
Recipients: gochimp3.CampaignCreationRecipients{
ListId: listId,
},
Settings: gochimp3.CampaignCreationSettings{
SubjectLine: "It's time to water the trees!",
Title: "NYC unestablished tree watering alert",
FromName: "Water Duty",
ReplyTo: "noreply@waterduty.org",
ToName: "NYC Tree Stewards",
TemplateId: templateId,
},
}
createCampaignResponse, err := client.CreateCampaign(&createCampaignRequest)
if err != nil {
return err
}
if createCampaignResponse == nil {
return err
}
_, err = client.SendCampaign(createCampaignResponse.ID, nil)
if err != nil {
return err
}
return nil
}