- Notifications
You must be signed in to change notification settings - Fork267
The Official Twilio SendGrid Golang API Library
License
sendgrid/sendgrid-go
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Go.
Version 3.X.X of this library provides full support for all Twilio SendGridWeb API v3 endpoints, including the newv3 /mail/send.
This library represents the beginning of a new path for Twilio SendGrid. We want this library to be community driven and Twilio SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you createissues andpull requests or simply upvote or comment on existing issues or pull requests.
If you need help using SendGrid, please check theTwilio SendGrid Support Help Center.
- Installation
- Quick Start
- Processing Inbound Email
- Usage
- Use Cases
- Announcements
- How to Contribute
- Troubleshooting
- About
- License
This library supports the following Go implementations:
- Go 1.14
- Go 1.15
- Go 1.16
- Go 1.17
- Go 1.18
- Go 1.19
- The Twilio SendGrid service, starting at thefree level, to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check outour pricing.
Update the development environment with yourSENDGRID_API_KEY, for example:
echo"export SENDGRID_API_KEY='YOUR_API_KEY'"> sendgrid.envecho"sendgrid.env">> .gitignoresource ./sendgrid.env
go get github.com/sendgrid/sendgrid-go
cp .env_sample .env
Update the development environment with yourSENDGRID_API_KEY, for example:
echo"export SENDGRID_API_KEY='YOUR_API_KEY'"> sendgrid.envecho"sendgrid.env">> .gitignoresource ./sendgrid.env
The following is the minimum needed code to send an email with the/mail/send Helper (here is a full example):
package mainimport ("fmt""log""os""github.com/sendgrid/sendgrid-go""github.com/sendgrid/sendgrid-go/helpers/mail")funcmain() {from:=mail.NewEmail("Example User","test@example.com")subject:="Sending with Twilio SendGrid is Fun"to:=mail.NewEmail("Example User","test@example.com")plainTextContent:="and easy to do anywhere, even with Go"htmlContent:="<strong>and easy to do anywhere, even with Go</strong>"message:=mail.NewSingleEmail(from,subject,to,plainTextContent,htmlContent)client:=sendgrid.NewSendClient(os.Getenv("SENDGRID_API_KEY"))response,err:=client.Send(message)iferr!=nil {log.Println(err)}else {fmt.Println(response.StatusCode)fmt.Println(response.Body)fmt.Println(response.Headers)}}
TheNewEmail
constructor creates apersonalization object for you.Here is an example of how to add to it.
The following is the minimum needed code to send an email without the /mail/send Helper (here is a full example):
package mainimport ("fmt""github.com/sendgrid/sendgrid-go""log""os")funcmain() {request:=sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"),"/v3/mail/send","https://api.sendgrid.com")request.Method="POST"request.Body= []byte(` {"personalizations": [{"to": [{"email": "test@example.com"}],"subject": "Sending with Twilio SendGrid is Fun"}],"from": {"email": "test@example.com"},"content": [{"type": "text/plain","value": "and easy to do anywhere, even with Go"}]}`)response,err:=sendgrid.API(request)iferr!=nil {log.Println(err)}else {fmt.Println(response.StatusCode)fmt.Println(response.Body)fmt.Println(response.Headers)}}
package mainimport ("fmt""github.com/sendgrid/sendgrid-go""log""os")funcmain() {request:=sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"),"/v3/api_keys","https://api.sendgrid.com")request.Method="GET"response,err:=sendgrid.API(request)iferr!=nil {log.Println(err)}else {fmt.Println(response.StatusCode)fmt.Println(response.Body)fmt.Println(response.Headers)}}
Please seeour helper for utilizing our Inbound Parse webhook.
- Twilio SendGrid Docs
- Library Usage Docs
- Example Code
- How-to: Migration from v2 to v3
- v3 Web API Mail Send Helper
Examples of common API use cases, such as how to send an email with a transactional template.
All updates to this library are documented in ourCHANGELOG andreleases.
We encourage contribution to our libraries (you might even score some nifty swag), please see ourCONTRIBUTING guide for details.
Quick links:
Please see ourtroubleshooting guide for common library issues.
sendgrid-go is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-go are trademarks of Twilio SendGrid, Inc.
If you need help using SendGrid, please check theTwilio SendGrid Support Help Center.
About
The Official Twilio SendGrid Golang API Library
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.