Skip to content

Instantly share code, notes, and snippets.

@elbuo8
Last active August 29, 2015 14:00
Show Gist options
  • Save elbuo8/11271846 to your computer and use it in GitHub Desktop.
Save elbuo8/11271846 to your computer and use it in GitHub Desktop.
Go AppEngine Post
application: your-app-name
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
context := appengine.NewContext(r)
sg.Client = urlfetch.Client(context)
package demo
import (
"appengine"
"appengine/urlfetch"
"github.com/go-martini/martini"
"github.com/sendgrid/sendgrid-go"
"net/http"
)
func init() {
sg := sendgrid.NewSendGridClient("SENDGRID_USERNAME", "SENDGRID_PASSWORD")
m := martini.Classic()
m.Get("/:email", func(r *http.Request, params martini.Params) string {
context := appengine.NewContext(r)
sg.Client = urlfetch.Client(context)
email := sendgrid.NewMail()
email.AddTo(params["email"])
email.SetSubject("Hello!")
email.SetText("This was sent from your sample app!")
email.SetFrom("yamil@sendgrid.com")
email.SetFromName("Yamil @elbuo8")
if e := sg.Send(email); e == nil {
return "Sent!"
} else {
context.Infof("%v", e)
return "Oups"
}
})
http.Handle("/", m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment