forked from domodwyer/mailyak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setters.go
137 lines (122 loc) · 3.48 KB
/
setters.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
package mailyak
import "mime"
// To sets a list of recipient addresses.
//
// You can pass one or more addresses to this method, all of which are viewable to the recipients.
//
// mail.To("dom@itsallbroken.com", "another@itsallbroken.com")
//
// or pass a slice of strings:
//
// tos := []string{
// "one@itsallbroken.com",
// "two@itsallbroken.com"
// }
//
// mail.To(tos...)
func (m *MailYak) To(addrs ...string) {
m.toAddrs = []string{}
for _, addr := range addrs {
trimmed := m.trimRegex.ReplaceAllString(addr, "")
if trimmed == "" {
continue
}
m.toAddrs = append(m.toAddrs, trimmed)
}
}
// Bcc sets a list of blind carbon copy (BCC) addresses.
//
// You can pass one or more addresses to this method, none of which are viewable to the recipients.
//
// mail.Bcc("dom@itsallbroken.com", "another@itsallbroken.com")
//
// or pass a slice of strings:
//
// bccs := []string{
// "one@itsallbroken.com",
// "two@itsallbroken.com"
// }
//
// mail.Bcc(bccs...)
func (m *MailYak) Bcc(addrs ...string) {
m.bccAddrs = []string{}
for _, addr := range addrs {
trimmed := m.trimRegex.ReplaceAllString(addr, "")
if trimmed == "" {
continue
}
m.bccAddrs = append(m.bccAddrs, trimmed)
}
}
// WriteBccHeader writes the BCC header to the MIME body when true. Defaults to
// false.
//
// This is usually required when writing the MIME body to an email API such as
// Amazon's SES, but can cause problems when sending emails via a SMTP server.
//
// Specifically, RFC822 says:
//
// Some systems may choose to include the text of the "Bcc" field only in the
// author(s)'s copy, while others may also include it in the text sent to
// all those indicated in the "Bcc" list.
//
// This ambiguity can result in some SMTP servers not stripping the BCC header
// and exposing the BCC addressees to recipients. For more information, see:
//
// https://github.com/domodwyer/mailyak/issues/14
//
func (m *MailYak) WriteBccHeader(shouldWrite bool) {
m.writeBccHeader = shouldWrite
}
// Cc sets a list of carbon copy (CC) addresses.
//
// You can pass one or more addresses to this method, which are viewable to the other recipients.
//
// mail.Cc("dom@itsallbroken.com", "another@itsallbroken.com")
//
// or pass a slice of strings:
//
// ccs := []string{
// "one@itsallbroken.com",
// "two@itsallbroken.com"
// }
//
// mail.Cc(ccs...)
func (m *MailYak) Cc(addrs ...string) {
m.ccAddrs = []string{}
for _, addr := range addrs {
trimmed := m.trimRegex.ReplaceAllString(addr, "")
if trimmed == "" {
continue
}
m.ccAddrs = append(m.ccAddrs, trimmed)
}
}
// From sets the sender email address.
//
// Users should also consider setting FromName().
func (m *MailYak) From(addr string) {
m.fromAddr = m.trimRegex.ReplaceAllString(addr, "")
}
// FromName sets the sender name.
//
// If set, emails typically display as being from:
//
// From Name <sender@example.com>
//
// If name contains non-ASCII characters, it is Q-encoded according to RFC1342.
func (m *MailYak) FromName(name string) {
m.fromName = mime.QEncoding.Encode("UTF-8", m.trimRegex.ReplaceAllString(name, ""))
}
// ReplyTo sets the Reply-To email address.
//
// Setting a ReplyTo address is optional.
func (m *MailYak) ReplyTo(addr string) {
m.replyTo = m.trimRegex.ReplaceAllString(addr, "")
}
// Subject sets the email subject line.
//
// If sub contains non-ASCII characters, it is Q-encoded according to RFC1342.
func (m *MailYak) Subject(sub string) {
m.subject = mime.QEncoding.Encode("UTF-8", m.trimRegex.ReplaceAllString(sub, ""))
}