Skip to content

Commit

Permalink
Make sure to set COSGO_DESTINATION and SENDGRID_KEY variables in heroku.
Browse files Browse the repository at this point in the history
I added a sendgrid key for quick setup
  • Loading branch information
aerth committed Apr 18, 2016
1 parent d1a2761 commit c2ea387
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: cosgo -quiet -debug -port=$PORT
web: cosgo -quiet -nolog -mailmode sendgrid -port=$PORT $FLAGS
17 changes: 15 additions & 2 deletions boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ func quickSelfTest() (err error) {
return errors.New("Fatal: environmental variable `MANDRILL_KEY` is Crucial.\n\n\t\tHint: export MANDRILL_KEY=123456789")

}
if cosgoDestination == "" {
cosgoDestination = os.Getenv("COSGO_DESTINATION")
if cosgoDestination == "" {
return errors.New("Fatal: environmental variable `COSGO_DESTINATION` is Crucial.\n\n\t\tHint: export [email protected]")
}
}
case smtpsendgrid:
sendgridKey = os.Getenv("SENDGRID_KEY")
if sendgridKey == "" {
return errors.New("Fatal: environmental variable `SENDGRID_KEY` is Crucial.\n\n\t\tHint: export SENDGRID_KEY=123456789")

sendgridKey = "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"
log.Println("Warning: Set SENDGRID_KEY variable for production usage.")
// return errors.New("Fatal: environmental variable `SENDGRID_KEY` is Crucial.\n\n\t\tHint: export SENDGRID_KEY=123456789")
}
if cosgoDestination == "" {
cosgoDestination = os.Getenv("COSGO_DESTINATION")
if cosgoDestination == "" {
return errors.New("Fatal: environmental variable `COSGO_DESTINATION` is Crucial.\n\n\t\tHint: export [email protected]")
}
}
default:
// No mailmode, going for mailbox.
Expand Down
9 changes: 7 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ func emailHandler(rw http.ResponseWriter, r *http.Request) {
// Switch on mailmode and send it out! Success message may change/be customized in the future.
switch *mailmode {
case smtpmandrill:
mandrillSender(rw, r, destination, query)
err = mandrillSender(rw, r, destination, query)
if err != nil {
log.Printf("FAILURE-contact: %s at %s\n\t%s", r.UserAgent(), r.RemoteAddr, query)
http.Redirect(rw, r, "/?status=0&r=5#contact ", http.StatusFound)
return
}
log.Printf("SUCCESS-contact: %s at %s", r.UserAgent(), r.RemoteAddr)
http.Redirect(rw, r, "/?status=1", http.StatusFound)
return
Expand All @@ -218,7 +223,7 @@ func emailHandler(rw http.ResponseWriter, r *http.Request) {
}
log.Printf("SUCCESS-contact: %s at %s", r.UserAgent(), r.RemoteAddr)
rw.Header().Add("status", "success")
homeHandler(rw, r)
http.Redirect(rw, r, "/?status=1", http.StatusFound)
return
default:
err = mbox.Save(form)
Expand Down
4 changes: 2 additions & 2 deletions sendgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func sendgridSend(destinationEmail string, form *Form) (ok bool, msg string) {
message.SetText(form.Message)
r := sg.Send(message)
if r == nil {
return true, string("Sendgrid Email sent from" + destinationEmail)
return true, string("Sendgrid: Email sent to " + destinationEmail)
}
return false, string("Sendgrid Error: (" + destinationEmail + ")" + r.Error())
return false, string("Sendgrid Error:" + r.Error())
}

// sendgridSender always returns success for the visitor. This function needs some work.
Expand Down

0 comments on commit c2ea387

Please sign in to comment.