Last active
August 29, 2015 14:00
-
-
Save elbuo8/11271846 to your computer and use it in GitHub Desktop.
Go AppEngine Post
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
application: your-app-name | |
version: 1 | |
runtime: go | |
api_version: go1 | |
handlers: | |
- url: /.* | |
script: _go_app |
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
context := appengine.NewContext(r) | |
sg.Client = urlfetch.Client(context) |
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
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