Skip to content

Commit 8f2cf2a

Browse files
committed
Max to, css and bcc recipients
1 parent 35d73b6 commit 8f2cf2a

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ You can view the generated [documentation here](https://godoc.org/github.com/mrz
4444

4545
### Features
4646
- Supports multiple service providers _(below)_
47+
- Support basic [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol)
4748
- Plain-text and HTML content
4849
- Multiple file attachments
4950
- Open & click tracking _(provider dependant)_
5051
- Inject css into html content
5152
- Basic template support
53+
- Max restrictions on To, CC and BCC
5254

5355
### Supported Service Providers
5456
- [AWS SES](https://docs.aws.amazon.com/ses/)

config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type MailService struct {
4242
FromUsername string `json:"from_username" mapstructure:"from_username"` // ie: no-reply
4343
Important bool `json:"important" mapstructure:"important"` // whether or not this message is important, and should be delivered ahead of non-important messages
4444
MandrillAPIKey string `json:"mandrill_api_key" mapstructure:"mandrill_api_key"` // mandrill api key
45+
MaxBccRecipients int `json:"max_bcc_recipients" mapstructure:"max_bcc_recipients"` // max amount for BCC
46+
MaxCcRecipients int `json:"max_cc_recipients" mapstructure:"max_cc_recipients"` // max amount for CC
47+
MaxToRecipients int `json:"max_to_recipients" mapstructure:"max_to_recipients"` // max amount for TO
4548
PostmarkServerToken string `json:"postmark_server_token" mapstructure:"postmark_server_token"` // ie: abc123...
4649
SMTPHost string `json:"smtp_host" mapstructure:"smtp_host"` // ie: example.com
4750
SMTPPassword string `json:"smtp_password" mapstructure:"smtp_password"` // ie: secretPassword
@@ -80,6 +83,9 @@ func (m *MailService) StartUp() (err error) {
8083

8184
// Set any defaults
8285
m.awsSesService.Endpoint = awsSesDefaultEndpoint
86+
m.MaxToRecipients = maxToRecipients
87+
m.MaxCcRecipients = maxCcRecipients
88+
m.MaxBccRecipients = maxBccRecipients
8389

8490
// If the key is set, try loading the service
8591
if len(m.MandrillAPIKey) > 0 {

email.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,22 @@ func (m *MailService) SendEmail(email *Email, provider ServiceProvider) (err err
166166
} else if len(email.Recipients) == 0 {
167167
err = fmt.Errorf("email is a recipient")
168168
return
169-
} else if len(email.Recipients) > maxToRecipients {
170-
err = fmt.Errorf("max TO recipient limit of %d reached: %d", maxToRecipients, len(email.Recipients))
169+
} else if len(email.Recipients) > m.MaxToRecipients {
170+
err = fmt.Errorf("max TO recipient limit of %d reached: %d", m.MaxToRecipients, len(email.Recipients))
171171
return
172-
} else if len(email.RecipientsCc) > maxCcRecipients {
173-
err = fmt.Errorf("max CC recipient limit of %d reached: %d", maxCcRecipients, len(email.RecipientsCc))
172+
} else if len(email.RecipientsCc) > m.MaxCcRecipients {
173+
err = fmt.Errorf("max CC recipient limit of %d reached: %d", m.MaxCcRecipients, len(email.RecipientsCc))
174174
return
175-
} else if len(email.RecipientsBcc) > maxBccRecipients {
176-
err = fmt.Errorf("max BCC recipient limit of %d reached: %d", maxBccRecipients, len(email.RecipientsBcc))
175+
} else if len(email.RecipientsBcc) > m.MaxBccRecipients {
176+
err = fmt.Errorf("max BCC recipient limit of %d reached: %d", m.MaxBccRecipients, len(email.RecipientsBcc))
177177
return
178178
}
179179

180180
// Send using given provider
181-
if provider == Mandrill {
182-
err = m.sendWithMandrill(email)
183-
} else if provider == AwsSes {
181+
if provider == AwsSes {
184182
err = m.sendWithAwsSes(email)
183+
} else if provider == Mandrill {
184+
err = m.sendWithMandrill(email)
185185
} else if provider == Postmark {
186186
err = m.sendWithPostmark(email)
187187
} else if provider == SMTP {

0 commit comments

Comments
 (0)