-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Twilio Email (#1093)
- Loading branch information
childish-sambino
authored
Apr 21, 2020
1 parent
6ef53e5
commit 39ea910
Showing
10 changed files
with
211 additions
and
82 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
This documentation provides examples for specific Twilio SendGrid v3 API use cases. Please [open an issue](https://github.com/sendgrid/sendgrid-nodejs/issues) or make a pull request for any email use cases you would like us to document here. Thank you! | ||
|
||
# Email Use Cases | ||
* [Send a Single Email to a Single Recipient](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/single-email-single-recipient.md) | ||
* [Send a Single Email to Multiple Recipients](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/single-email-multiple-recipients.md) | ||
* [Send Multiple Emails to Multiple Recipients](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/multiple-emails-multiple-recipients.md) | ||
* [CC, BCC and Reply To](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/cc-bcc-reply-to.md) | ||
* [Flexible Email Address Fields](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/flexible-address-fields.md) | ||
* [Handling Success/Failure/Errors](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/success-failure-errors.md) | ||
* [Show Email Activity](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/email-activity.md) | ||
* [Advanced Usage](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/advanced.md) | ||
* [Transactional Templates](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/transactional-templates.md) | ||
* [Legacy Transactional Templates](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/transactional-legacy-templates.md) | ||
* [Hide Warnings](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/hide-warnings.md) | ||
* [Attachments](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/attachments.md) | ||
* [Customization Per Recipient](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/customization.md) | ||
* [Manually Providing Content](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/manual-content.md) | ||
* [Specifying Time to Send At](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/time-to-send.md) | ||
* [Specifying Custom Headers](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/custom-headers.md) | ||
* [Specifying Categories](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/categories.md) | ||
* [Timeout](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/timeout.md) | ||
* [Kitchen Sink - an example with all settings used](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/kitchen-sink.md) | ||
* [Send a Single Email to a Single Recipient](single-email-single-recipient.md) | ||
* [Send a Single Email to Multiple Recipients](single-email-multiple-recipients.md) | ||
* [Send Multiple Emails to Multiple Recipients](multiple-emails-multiple-recipients.md) | ||
* [CC, BCC and Reply To](cc-bcc-reply-to.md) | ||
* [Flexible Email Address Fields](flexible-address-fields.md) | ||
* [Handling Success/Failure/Errors](success-failure-errors.md) | ||
* [Show Email Activity](email-activity.md) | ||
* [Advanced Usage](advanced.md) | ||
* [Transactional Templates](transactional-templates.md) | ||
* [Legacy Transactional Templates](transactional-legacy-templates.md) | ||
* [Hide Warnings](hide-warnings.md) | ||
* [Attachments](attachments.md) | ||
* [Customization Per Recipient](customization.md) | ||
* [Manually Providing Content](manual-content.md) | ||
* [Specifying Time to Send At](time-to-send.md) | ||
* [Specifying Custom Headers](custom-headers.md) | ||
* [Specifying Categories](categories.md) | ||
* [Timeout](timeout.md) | ||
* [Kitchen Sink - an example with all settings used](kitchen-sink.md) | ||
|
||
# Twilio Use Cases | ||
* [Twilio Setup](twilio-setup.md) | ||
* [Send an Email With Twilio Email (Pilot)](twilio-email.md) | ||
* [Send an SMS Message](sms.md) | ||
|
||
# Non-Email Use Cases | ||
* [Send a SMS Message](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/sms.md) | ||
* [How to Setup a Domain Whitelabel](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/domain-white-label.md) | ||
* [How to View Email Statistics](https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/email-stats.md) | ||
* [How to Set up a Domain Whitelabel](domain-white-label.md) | ||
* [How to View Email Statistics](email-stats.md) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
First, follow the [Twilio Setup](twilio-setup.md) guide for creating a Twilio account and setting up environment variables with the proper credentials. | ||
|
||
Then, initialize the Twilio Email Client. | ||
|
||
```js | ||
const client = require('@sendgrid/client'); | ||
|
||
client.setTwilioEmailAuth(process.env.TWILIO_API_KEY, process.env.TWILIO_API_SECRET); | ||
|
||
// or | ||
|
||
client.setTwilioEmailAuth(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN); | ||
``` | ||
|
||
Or similarly using the mail helper. | ||
|
||
```js | ||
const mail = require('@sendgrid/mail'); | ||
|
||
mail.setTwilioEmailAuth(process.env.TWILIO_API_KEY, process.env.TWILIO_API_SECRET); | ||
|
||
// or | ||
|
||
mail.setTwilioEmailAuth(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN); | ||
``` | ||
|
||
This sets the client to use Twilio Auth and the Twilio Email API. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## 1. Obtain a Free Twilio Account | ||
|
||
Sign up for a free Twilio account [here](https://www.twilio.com/try-twilio?source=sendgrid-nodejs). | ||
|
||
## 2. Set Up Your Environment Variables | ||
|
||
The Twilio API allows for authentication using with either an API key/secret or your Account SID/Auth Token. You can create an API key [here](https://twil.io/get-api-key) or obtain your Account SID and Auth Token [here](https://twil.io/console). | ||
|
||
Once you have those, follow the steps below based on your operating system. | ||
|
||
### Linux/Mac | ||
|
||
```bash | ||
echo "export TWILIO_API_KEY='YOUR_TWILIO_API_KEY'" > twilio.env | ||
echo "export TWILIO_API_SECRET='YOUR_TWILIO_API_SECRET'" >> twilio.env | ||
|
||
# or | ||
|
||
echo "export TWILIO_ACCOUNT_SID='YOUR_TWILIO_ACCOUNT_SID'" > twilio.env | ||
echo "export TWILIO_AUTH_TOKEN='YOUR_TWILIO_AUTH_TOKEN'" >> twilio.env | ||
``` | ||
|
||
Then: | ||
|
||
```bash | ||
echo "twilio.env" >> .gitignore | ||
source ./twilio.env | ||
``` | ||
|
||
### Windows | ||
|
||
Temporarily set the environment variable (accessible only during the current CLI session): | ||
|
||
```bash | ||
set TWILIO_API_KEY=YOUR_TWILIO_API_KEY | ||
set TWILIO_API_SECRET=YOUR_TWILIO_API_SECRET | ||
|
||
: or | ||
|
||
set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID | ||
set TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN | ||
``` | ||
|
||
Or permanently set the environment variable (accessible in all subsequent CLI sessions): | ||
|
||
```bash | ||
setx TWILIO_API_KEY "YOUR_TWILIO_API_KEY" | ||
setx TWILIO_API_SECRET "YOUR_TWILIO_API_SECRET" | ||
|
||
: or | ||
|
||
setx TWILIO_ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID" | ||
setx TWILIO_AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN" | ||
``` |
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
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
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
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
Oops, something went wrong.