|
2 | 2 | [](https://badge.fury.io/js/sendgrid)
|
3 | 3 | [](https://dx.sendgrid.com/newsletter/nodejs)
|
4 | 4 |
|
5 |
| -**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/nodejs) for releases and breaking changes. |
6 |
| - |
7 | 5 | **This library allows you to quickly and easily use the SendGrid Web API v3 via Node.js.**
|
8 | 6 |
|
9 |
| -Version 3.X.X+ of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint). |
| 7 | +We want this library to be community driven and 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 create [issues](https://github.com/sendgrid/sendgrid-nodejs/issues) and [pull requests](https://github.com/sendgrid/sendgrid-nodejs/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests. |
10 | 8 |
|
11 |
| -This library represents the beginning of a new path for SendGrid. We want this library to be community driven and 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 create [issues](https://github.com/sendgrid/sendgrid-nodejs/issues) and [pull requests](https://github.com/sendgrid/sendgrid-nodejs/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests. |
| 9 | +To be notified when this package is updated, please subscribe to email [notifications](https://dx.sendgrid.com/newsletter/nodejs) for releases and breaking changes. |
12 | 10 |
|
13 | 11 | Please browse the rest of this README for further detail.
|
14 | 12 |
|
15 | 13 | We appreciate your continued support, thank you!
|
16 | 14 |
|
17 | 15 | # Table of Contents
|
18 | 16 |
|
19 |
| -* [Installation](#installation) |
20 |
| -* [Quick Start](#quick_start) |
21 |
| -* [Usage](#usage) |
22 |
| -* [Use Cases](#use_cases) |
| 17 | +* [Introduction - Please Read First](#introduction) |
| 18 | +* [Additional Documentation](#usage) |
23 | 19 | * [Announcements](#announcements)
|
24 | 20 | * [Roadmap](#roadmap)
|
25 | 21 | * [How to Contribute](#contribute)
|
26 | 22 | * [Troubleshooting](#troubleshooting)
|
27 | 23 | * [About](#about)
|
28 | 24 |
|
29 |
| -<a name="installation"></a> |
30 |
| -# Installation |
31 |
| - |
32 |
| -## Prerequisites |
33 |
| - |
34 |
| -- Node.js version 4, 6 or 7 |
35 |
| -- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-nodejs) |
36 |
| - |
37 |
| -## Setup Environment Variables |
38 |
| - |
39 |
| -Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example: |
40 |
| - |
41 |
| -```bash |
42 |
| -echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env |
43 |
| -echo "sendgrid.env" >> .gitignore |
44 |
| -source ./sendgrid.env |
45 |
| -``` |
46 |
| - |
47 |
| -## Install Package |
48 |
| - |
49 |
| -The following recommended installation requires [npm](https://npmjs.org/). If you are unfamiliar with npm, see the [npm docs](https://npmjs.org/doc/). Npm comes installed with Node.js since node version 0.8.x therefore you likely already have it. |
50 |
| - |
51 |
| -```bash |
52 |
| -npm install --save sendgrid |
53 |
| -``` |
54 |
| - |
55 |
| -## Dependencies |
56 |
| - |
57 |
| -- [Nodejs-HTTP-Client](https://github.com/sendgrid/nodejs-http-client) |
58 |
| - |
59 |
| -<a name="quick_start"></a> |
60 |
| -# Quick Start |
61 |
| - |
62 |
| -## Hello Email |
63 |
| - |
64 |
| -The following is the minimum needed code to send an email with the [/mail/send Helper](https://github.com/sendgrid/sendgrid-nodejs/tree/master/lib/helpers/mail) ([here](https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/helpers/mail/example.js#L15) is a full example): |
65 |
| - |
66 |
| -### With Mail Helper Class |
67 |
| - |
68 |
| -```javascript |
69 |
| -var helper = require('sendgrid').mail; |
70 |
| -var fromEmail = new helper.Email( '[email protected]'); |
71 |
| -var toEmail = new helper.Email( '[email protected]'); |
72 |
| -var subject = 'Sending with SendGrid is Fun'; |
73 |
| -var content = new helper.Content('text/plain', 'and easy to do anywhere, even with Node.js'); |
74 |
| -var mail = new helper.Mail(fromEmail, subject, toEmail, content); |
75 |
| - |
76 |
| -var sg = require('sendgrid')(process.env.SENDGRID_API_KEY); |
77 |
| -var request = sg.emptyRequest({ |
78 |
| - method: 'POST', |
79 |
| - path: '/v3/mail/send', |
80 |
| - body: mail.toJSON() |
81 |
| -}); |
82 |
| - |
83 |
| -sg.API(request, function (error, response) { |
84 |
| - if (error) { |
85 |
| - console.log('Error response received'); |
86 |
| - } |
87 |
| - console.log(response.statusCode); |
88 |
| - console.log(response.body); |
89 |
| - console.log(response.headers); |
90 |
| -}); |
91 |
| -``` |
92 |
| - |
93 |
| -The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/helpers/mail/example.js#L10) is an example of how to add to it. |
94 |
| - |
95 |
| -### Without Mail Helper Class |
96 |
| - |
97 |
| -The following is the minimum needed code to send an email without the /mail/send Helper ([here](https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/mail/mail.js#L31) is a full example): |
98 |
| - |
99 |
| -```javascript |
100 |
| -var sg = require('sendgrid')(process.env.SENDGRID_API_KEY); |
101 |
| -var request = sg.emptyRequest({ |
102 |
| - method: 'POST', |
103 |
| - path: '/v3/mail/send', |
104 |
| - body: { |
105 |
| - personalizations: [ |
106 |
| - { |
107 |
| - to: [ |
108 |
| - { |
109 |
| - |
110 |
| - } |
111 |
| - ], |
112 |
| - subject: 'Sending with SendGrid is Fun' |
113 |
| - } |
114 |
| - ], |
115 |
| - from: { |
116 |
| - |
117 |
| - }, |
118 |
| - content: [ |
119 |
| - { |
120 |
| - type: 'text/plain', |
121 |
| - value: 'and easy to do anywhere, even with Node.js' |
122 |
| - } |
123 |
| - ] |
124 |
| - } |
125 |
| -}); |
126 |
| - |
127 |
| -// With promise |
128 |
| -sg.API(request) |
129 |
| - .then(function (response) { |
130 |
| - console.log(response.statusCode); |
131 |
| - console.log(response.body); |
132 |
| - console.log(response.headers); |
133 |
| - }) |
134 |
| - .catch(function (error) { |
135 |
| - // error is an instance of SendGridError |
136 |
| - // The full response is attached to error.response |
137 |
| - console.log(error.response.statusCode); |
138 |
| - }); |
139 |
| - |
140 |
| -// With callback |
141 |
| -sg.API(request, function (error, response) { |
142 |
| - if (error) { |
143 |
| - console.log('Error response received'); |
144 |
| - } |
145 |
| - console.log(response.statusCode); |
146 |
| - console.log(response.body); |
147 |
| - console.log(response.headers); |
148 |
| -}); |
149 |
| -``` |
150 |
| - |
151 |
| -## General v3 Web API Usage |
152 |
| - |
153 |
| -```javascript |
154 |
| -var sg = require('sendgrid')(process.env.SENDGRID_API_KEY); |
155 |
| - |
156 |
| -// GET Collection |
157 |
| -var request = sg.emptyRequest({ |
158 |
| - method: 'GET', |
159 |
| - path: '/v3/api_keys' |
160 |
| -}); |
161 |
| - |
162 |
| -// With promise |
163 |
| -sg.API(request) |
164 |
| - .then(function (response) { |
165 |
| - console.log(response.statusCode); |
166 |
| - console.log(response.body); |
167 |
| - console.log(response.headers); |
168 |
| - }) |
169 |
| - .catch(function (error) { |
170 |
| - // error is an instance of SendGridError |
171 |
| - // The full response is attached to error.response |
172 |
| - console.log(error.response.statusCode); |
173 |
| - }); |
174 |
| - |
175 |
| -// With callback |
176 |
| -sg.API(request, function (error, response) { |
177 |
| - if (error) { |
178 |
| - console.log('Error response received'); |
179 |
| - } |
180 |
| - console.log(response.statusCode); |
181 |
| - console.log(response.body); |
182 |
| - console.log(response.headers); |
183 |
| -}); |
184 |
| -``` |
185 |
| - |
186 |
| -<a name="usage"></a> |
187 |
| -# Usage |
188 |
| - |
189 |
| -- [SendGrid Docs](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) |
190 |
| -- [Library Usage Docs](https://github.com/sendgrid/sendgrid-nodejs/blob/master/USAGE.md) |
191 |
| -- [Example Code](https://github.com/sendgrid/sendgrid-nodejs/tree/master/examples) |
192 |
| -- [How-to: Migration from v2 to v3](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) |
193 |
| -- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-nodejs/tree/master/lib/helpers/mail/README.md) |
194 |
| - |
195 |
| -<a name="use_cases"></a> |
196 |
| -# Use Cases |
197 |
| - |
198 |
| -[Examples of common API use cases](https://github.com/sendgrid/sendgrid-nodejs/blob/master/USE_CASES.md), such as how to send an email with a transactional template. |
| 25 | +<a name="introduction"></a> |
| 26 | +# Introduction |
| 27 | + |
| 28 | +This library is broken up into several packages as a monorepo so that you only need to install the packages necessary for your use case. This README contains information pertaining to all packages. |
| 29 | + |
| 30 | +* [@sendgrid/mail](https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail) - if you just want to send email |
| 31 | +* [@sendgrid/client](https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/client) - to use all other [SendGrid v3 Web API endpoints](https://sendgrid.com/docs/API_Reference/api_v3.html) |
| 32 | +* [@sendgrid/inbound-mail-parser](https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/inbound-mail-parser) - help with parsing the SendGrid Inbound Parse API |
| 33 | +* [@sendgrid/contact-import](https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/contact-import) - help with importing contacts into the ContactDB |
| 34 | +* [@sendgrid/helpers](https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/helpers) - a collection of classes and helpers used internally by the above packages |
199 | 35 |
|
200 | 36 | <a name="announcements"></a>
|
201 | 37 | # Announcements
|
202 | 38 |
|
203 |
| -Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-nodejs/issues/290). Your support is appreciated! |
204 |
| - |
205 | 39 | All updates to this library are documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-nodejs/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-nodejs/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/nodejs) for releases and breaking changes.
|
206 | 40 |
|
207 | 41 | <a name="roadmap"></a>
|
|
0 commit comments