sts-sendgrid
v3.0.8
Published
Official SendGrid NodeJS library.
Downloads
3
Readme
This library allows you to quickly and easily use the SendGrid Web API via Node.js.
Announcements
BREAKING CHANGE as of 2016.06.14
Version 3.X.X brings you full support for all Web API v3 endpoints. We have the following resources to get you started quickly:
Thank you for your continued support!
All updates to this library is documented in our CHANGELOG.
Installation
Prerequisites
- Node.js version 0.10, 0.12 or 4
- The SendGrid service, starting at the free level
Setup Environment Variables
Update your environment with your SENDGRID_API_KEY.
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
Install Package
The following recommended installation requires npm. If you are unfamiliar with npm, see the npm docs. Npm comes installed with Node.js since node version 0.8.x therefore you likely already have it.
Add the following to your package.json
file:
{
...
"dependencies": {
...
"sendgrid": "^3.0.8"
}
}
Install sendgrid-nodejs and its dependencies:
npm install
Alternative Installation
You can also install sendgrid locally with the following command:
npm install sendgrid
Dependencies
Quick Start
Hello Email
var helper = require('sendgrid').mail
from_email = new helper.Email("[email protected]")
to_email = new helper.Email("[email protected]")
subject = "Hello World from the SendGrid Node.js Library"
content = new helper.Content("text/plain", "some text here")
mail = new helper.Mail(from_email, subject, to_email, content)
var sg = require('sendgrid').SendGrid(process.env.SENDGRID_API_KEY)
var requestBody = mail.toJSON()
var request = sg.emptyRequest()
request.method = 'POST'
request.path = '/v3/mail/send'
request.body = requestBody
sg.API(request, function (response) {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
})
General v3 Web API Usage
var sg = require('sendgrid').SendGrid(process.env.SENDGRID_API_KEY)
// GET Collection
var request = sg.emptyRequest()
request.method = 'GET'
request.path = '/v3/api_keys'
sg.API(request, function (response) {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
})
Usage
Roadmap
If you are intersted in the future direction of this project, please take a look at our milestones. We would love to hear your feedback.
How to Contribute
We encourage contribution to our libraries, please see our CONTRIBUTING guide for details.
About
sendgrid-nodejs is guided and supported by the SendGrid Developer Experience Team.
sendgrid-nodejs is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-nodejs are trademarks of SendGrid, Inc.
![SendGrid Logo] (https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)