-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a14145
Showing
5 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/aws/aws-sdk-go" | ||
version = "1.13.16" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/davidbanham/required_env" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package notifications | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ses" | ||
"github.com/davidbanham/required_env" | ||
) | ||
|
||
var svc *ses.SES | ||
var testMode bool | ||
|
||
func init() { | ||
if os.Getenv("TEST_MOCKS_ON") == "true" { | ||
testMode = true | ||
return | ||
} | ||
required_env.Ensure(map[string]string{ | ||
"AWS_ACCESS_KEY_ID": "", | ||
"AWS_SECRET_ACCESS_KEY": "", | ||
}) | ||
sess, err := session.NewSession(&aws.Config{ | ||
Region: aws.String("us-east-1"), | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
svc = ses.New(sess) | ||
} | ||
|
||
type Email struct { | ||
To string | ||
From string | ||
ReplyTo string | ||
Text string | ||
HTML string | ||
Subject string | ||
} | ||
|
||
func SendEmail(email Email) (err error) { | ||
if testMode { | ||
log.Println("INFO notifications TESTMODE dropping email to", email.To, "from", email.From) | ||
return | ||
} | ||
log.Println("INFO notifications sending email to", email.To, "from", email.From) | ||
|
||
body := &ses.Body{ | ||
Text: &ses.Content{ | ||
Data: aws.String(email.Text), | ||
Charset: aws.String("UTF8"), | ||
}, | ||
} | ||
|
||
if email.HTML != "" { | ||
body.Html = &ses.Content{ | ||
Data: aws.String(email.HTML), | ||
Charset: aws.String("UTF8"), | ||
} | ||
} | ||
|
||
params := &ses.SendEmailInput{ | ||
Destination: &ses.Destination{ | ||
ToAddresses: []*string{ | ||
aws.String(email.To), | ||
}, | ||
}, | ||
Message: &ses.Message{ | ||
Body: body, | ||
Subject: &ses.Content{ | ||
Data: aws.String(email.Subject), | ||
Charset: aws.String("UTF8"), | ||
}, | ||
}, | ||
Source: aws.String(email.From), | ||
ReplyToAddresses: []*string{ | ||
aws.String(email.ReplyTo), | ||
}, | ||
} | ||
_, err = svc.SendEmail(params) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package notifications | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNotificationsLive(t *testing.T) { | ||
err := SendEmail(Email{ | ||
To: "david@banham.id.au", | ||
From: "testrun@takehome.io", | ||
ReplyTo: "lolwut@takehome.io", | ||
Text: "this is a test run", | ||
HTML: "this <i>is a test</i> run", | ||
Subject: "test run", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |