summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/goamz/goamz/exp/ses/ses_types.go
blob: 698fa7623c718fed624e1976b40a13cf5660ee24 (plain)
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
// ses_types
package ses

// Private internal representation of message body.
type Body struct {
	Html Content
	Text Content
}

// Content data structure with charset and payload (Data).
type Content struct {
	Charset string
	Data    string
}

// Email data structure. Should be main data structure used
// for sending emails using SES.
type Email struct {
	destination *destination
	message     Message
	replyTo     []string
	returnPath  string
	source      string
}

// Private internal representation for email destinations.
type destination struct {
	bccAddresses []string
	ccAddresses  []string
	toAddresses  []string
}

// Message data structure.
type Message struct {
	Body    Body
	Subject Content
}

// SES Error structure.
type SESError struct {
	Type      string
	Code      string
	Message   string
	Detail    string
	RequestId string
}

func (err *SESError) Error() string {
	return err.Message
}

// Returns a pointer to an empty but initialized Email.
func NewEmail() *Email {
	return &Email{
		destination: newDestination(),
		replyTo:     make([]string, 5)}
}

// Private function to return an initialized destination.
func newDestination() *destination {
	return &destination{
		bccAddresses: make([]string, 5),
		ccAddresses:  make([]string, 5),
		toAddresses:  make([]string, 5)}
}

// Add a BCC destination to Email.
func (em *Email) AddBCC(address string) {
	em.destination.bccAddresses = append(em.destination.bccAddresses, address)
}

// Add multiple BCC destinations to Email.
func (em *Email) AddBCCs(addresses []string) {
	em.destination.bccAddresses = append(em.destination.bccAddresses, addresses...)
}

// Add a CC destination to Email.
func (em *Email) AddCC(address string) {
	em.destination.ccAddresses = append(em.destination.ccAddresses, address)
}

// Add multiple CC destinations to Email.
func (em *Email) AddCCs(addresses []string) {
	em.destination.ccAddresses = append(em.destination.ccAddresses, addresses...)
}

// Add a To destination to Email.
func (em *Email) AddTo(address string) {
	em.destination.toAddresses = append(em.destination.toAddresses, address)
}

// Add multiple To destinations to Email.
func (em *Email) AddTos(addresses []string) {
	em.destination.toAddresses = append(em.destination.toAddresses, addresses...)
}

// Add a reply-to address to Email.
func (em *Email) AddReplyTo(address string) {
	em.replyTo = append(em.replyTo, address)
}

// Add multiple reply-to addresses to Email.
func (em *Email) AddReplyTos(addresses []string) {
	em.replyTo = append(em.replyTo, addresses...)
}

// Set the return path for Email.
func (em *Email) SetReturnPath(path string) {
	em.returnPath = path
}

// Set the source address for Email.
func (em *Email) SetSource(source string) {
	em.source = source
}

// Set the Email message.
func (em *Email) SetMessage(message Message) {
	em.message = message
}

// Set the subject for the Email message.
// Uses ASCII as charset.
func (em *Email) SetSubject(subject string) {
	em.message.Subject = Content{Data: subject}
}

// Set the subject for the Email message.
// Uses the charset (or ASCII if none) of Content.
func (em *Email) SetSubjectAsContent(subject Content) {
	em.message.Subject = subject
}

// Sets the HTML body of the Email message.
// Uses ASCII as charset.
func (em *Email) SetBodyHtml(html string) {
	em.message.Body.Html = Content{Data: html}
}

// Sets the HTML body of the Email message.
// Uses the charset (or ASCII if none) of Content.
func (em *Email) SetBodyHtmlAsContent(html Content) {
	em.message.Body.Html = html
}

// Sets the raw text body of the Email message.
// Uses ASCII as charset.
func (em *Email) SetBodyRawText(text string) {
	em.message.Body.Text = Content{Data: text}
}

// Sets the raw test body of the Email message.
// Uses the charset (or ASCII if none) of Content.
func (em *Email) SetBodyRawTextAsContent(text Content) {
	em.message.Body.Text = text
}