Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The Official Twilio SendGrid Golang API Library

License

NotificationsYou must be signed in to change notification settings

sendgrid/sendgrid-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Twilio SendGrid Logo

Test and DeployGoDocMIT licensedTwitter FollowGitHub contributorsOpen Source Helpers

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.

Table of Contents

Installation

Supported Versions

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

Prerequisites

  • 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.

Setup Environment Variables

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

Install Package

go get github.com/sendgrid/sendgrid-go

Dependencies

Setup Environment Variables

Initial Setup

cp .env_sample .env

Environment Variable

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

Quick Start

Hello Email

The following is the minimum needed code to send an email with the/mail/send Helper (here is a full example):

With Mail Helper Class

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.

Without Mail Helper Class

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)}}

General v3 Web API Usage

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)}}

Processing Inbound Email

Please seeour helper for utilizing our Inbound Parse webhook.

Usage

Use Cases

Examples of common API use cases, such as how to send an email with a transactional template.

Announcements

All updates to this library are documented in ourCHANGELOG andreleases.

How to Contribute

We encourage contribution to our libraries (you might even score some nifty swag), please see ourCONTRIBUTING guide for details.

Quick links:

Troubleshooting

Please see ourtroubleshooting guide for common library issues.

About

sendgrid-go is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-go are trademarks of Twilio SendGrid, Inc.

Support

If you need help using SendGrid, please check theTwilio SendGrid Support Help Center.

License

The MIT License (MIT)

About

The Official Twilio SendGrid Golang API Library

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp