sendgrid-ruby 1.1.6 → 6.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.env_sample +1 -3
- data/.github/ISSUE_TEMPLATE/config.yml +10 -0
- data/.github/workflows/test-and-deploy.yml +120 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +5 -27
- data/.rubocop_todo.yml +127 -0
- data/CHANGELOG.md +417 -1
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +202 -0
- data/Dockerfile +14 -0
- data/FIRST_TIMERS.md +79 -0
- data/Gemfile +4 -4
- data/ISSUE_TEMPLATE.md +30 -0
- data/LICENSE +21 -0
- data/Makefile +14 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +153 -229
- data/Rakefile +9 -3
- data/TROUBLESHOOTING.md +151 -0
- data/UPGRADE.md +5 -0
- data/USAGE.md +5144 -0
- data/config.ru +4 -0
- data/examples/accesssettings/accesssettings.rb +80 -0
- data/examples/alerts/alerts.rb +59 -0
- data/examples/apikeys/apikeys.rb +81 -0
- data/examples/asm/asm.rb +170 -0
- data/examples/browsers/browsers.rb +13 -0
- data/examples/campaigns/campaigns.rb +150 -0
- data/examples/categories/categories.rb +33 -0
- data/examples/clients/clients.rb +24 -0
- data/examples/contactdb/contactdb.rb +392 -0
- data/examples/devices/devices.rb +13 -0
- data/examples/emailactivity/emailactivity.rb +52 -0
- data/examples/geo/geo.rb +13 -0
- data/examples/helpers/eventwebhook/example.rb +16 -0
- data/examples/helpers/mail/example.rb +158 -0
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +164 -0
- data/examples/mail/mail.rb +170 -0
- data/examples/mailboxproviders/mailboxproviders.rb +13 -0
- data/examples/mailsettings/mailsettings.rb +216 -0
- data/examples/partnersettings/partnersettings.rb +36 -0
- data/examples/scopes/scopes.rb +59 -0
- data/examples/senderauthentication/senderauthentication.rb +307 -0
- data/examples/senders/senders.rb +95 -0
- data/examples/stats/stats.rb +13 -0
- data/examples/subusers/subusers.rb +166 -0
- data/examples/suppression/suppression.rb +198 -0
- data/examples/templates/templates.rb +127 -0
- data/examples/trackingsettings/trackingsettings.rb +107 -0
- data/examples/user/user.rb +290 -0
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/rack/sendgrid_webhook_verification.rb +55 -0
- data/lib/sendgrid/base_interface.rb +40 -0
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
- data/lib/sendgrid/helpers/inbound/README.md +98 -0
- data/lib/sendgrid/helpers/inbound/app.rb +32 -0
- data/lib/sendgrid/helpers/inbound/config.yml +26 -0
- data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
- data/lib/sendgrid/helpers/inbound/send.rb +26 -0
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +14 -0
- data/lib/sendgrid/helpers/mail/asm.rb +19 -0
- data/lib/sendgrid/helpers/mail/attachment.rb +55 -0
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +19 -0
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +31 -0
- data/lib/sendgrid/helpers/mail/category.rb +18 -0
- data/lib/sendgrid/helpers/mail/click_tracking.rb +19 -0
- data/lib/sendgrid/helpers/mail/content.rb +19 -0
- data/lib/sendgrid/helpers/mail/custom_arg.rb +18 -0
- data/lib/sendgrid/helpers/mail/email.rb +32 -0
- data/lib/sendgrid/helpers/mail/footer.rb +21 -0
- data/lib/sendgrid/helpers/mail/ganalytics.rb +28 -0
- data/lib/sendgrid/helpers/mail/header.rb +18 -0
- data/lib/sendgrid/helpers/mail/mail.rb +122 -0
- data/lib/sendgrid/helpers/mail/mail_settings.rb +45 -0
- data/lib/sendgrid/helpers/mail/open_tracking.rb +19 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +93 -0
- data/lib/sendgrid/helpers/mail/section.rb +18 -0
- data/lib/sendgrid/helpers/mail/spam_check.rb +21 -0
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +23 -0
- data/lib/sendgrid/helpers/mail/substitution.rb +18 -0
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +39 -0
- data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
- data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
- data/lib/sendgrid/helpers/settings/README.md +14 -0
- data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/settings.rb +28 -0
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +22 -0
- data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
- data/lib/sendgrid/helpers/stats/metrics.rb +33 -0
- data/lib/sendgrid/helpers/stats/stats_response.rb +29 -0
- data/lib/sendgrid/sendgrid.rb +21 -0
- data/lib/sendgrid/twilio_email.rb +21 -0
- data/lib/sendgrid/version.rb +1 -1
- data/lib/sendgrid-ruby.rb +32 -7
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +16 -20
- data/spec/fixtures/event_webhook.rb +22 -0
- data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +111 -0
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +45 -0
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +75 -0
- data/spec/sendgrid/sendgrid_spec.rb +11 -0
- data/spec/sendgrid/twilio_email_spec.rb +11 -0
- data/spec/spec_helper.rb +12 -1
- data/static/img/github-fork.png +0 -0
- data/static/img/github-sign-up.png +0 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +33 -0
- data/test/sendgrid/helpers/mail/test_category.rb +25 -0
- data/test/sendgrid/helpers/mail/test_email.rb +41 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +260 -0
- data/test/sendgrid/helpers/mail/test_personalizations.rb +214 -0
- data/test/sendgrid/permissions/test_scopes.rb +36 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +2729 -0
- data/twilio_sendgrid_logo.png +0 -0
- data/use-cases/README.md +17 -0
- data/use-cases/domain-authentication.md +5 -0
- data/use-cases/email-statistics.md +52 -0
- data/use-cases/legacy-templates.md +98 -0
- data/use-cases/personalizations.md +34 -0
- data/use-cases/sms.md +39 -0
- data/use-cases/transactional-templates.md +111 -0
- data/use-cases/twilio-email.md +13 -0
- data/use-cases/twilio-setup.md +54 -0
- metadata +187 -112
- data/.rspec +0 -2
- data/.travis.yml +0 -20
- data/FETCH_HEAD +0 -0
- data/Guardfile +0 -10
- data/LICENSE.txt +0 -22
- data/example.rb +0 -41
- data/lib/sendgrid/client.rb +0 -62
- data/lib/sendgrid/exceptions.rb +0 -7
- data/lib/sendgrid/mail.rb +0 -182
- data/lib/sendgrid/recipient.rb +0 -29
- data/lib/sendgrid/response.rb +0 -14
- data/lib/sendgrid/template.rb +0 -26
- data/lib/sendgrid/template_mailer.rb +0 -59
- data/spec/lib/sendgrid/client_spec.rb +0 -87
- data/spec/lib/sendgrid/mail_spec.rb +0 -151
- data/spec/lib/sendgrid/recipient_spec.rb +0 -91
- data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
- data/spec/lib/sendgrid/template_spec.rb +0 -61
- data/spec/lib/sendgrid_spec.rb +0 -7
data/README.md
CHANGED
@@ -1,296 +1,220 @@
|
|
1
|
-
|
1
|
+
![Twilio SendGrid Logo](twilio_sendgrid_logo.png)
|
2
2
|
|
3
|
-
|
3
|
+
[![Travis Badge](https://github.com/sendgrid/sendgrid-ruby/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/sendgrid-ruby/actions/workflows/test-and-deploy.yml)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby)
|
5
|
+
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
|
6
|
+
[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
|
7
|
+
[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-ruby.svg)](https://github.com/sendgrid/sendgrid-ruby/graphs/contributors)
|
8
|
+
[![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-ruby/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-ruby)
|
4
9
|
|
5
|
-
|
10
|
+
**The default branch name for this repository has been changed to `main` as of 07/27/2020.**
|
6
11
|
|
7
|
-
|
12
|
+
**This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Ruby.**
|
8
13
|
|
14
|
+
Version 3.X.X+ of this library provides full support for all Twilio 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).
|
9
15
|
|
10
|
-
|
16
|
+
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 create [issues](https://github.com/sendgrid/sendgrid-ruby/issues) and [pull requests](CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests.
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
gem 'sendgrid-ruby'
|
15
|
-
|
16
|
-
And then execute:
|
18
|
+
Please browse the rest of this README for further details.
|
17
19
|
|
18
|
-
|
20
|
+
We appreciate your continued support, thank you!
|
19
21
|
|
20
|
-
|
22
|
+
# Table of Contents
|
21
23
|
|
22
|
-
|
24
|
+
* [Announcements](#announcements)
|
25
|
+
* [Installation](#installation)
|
26
|
+
* [Quick Start](#quick-start)
|
27
|
+
* [Processing Inbound Email](#inbound)
|
28
|
+
* [Usage](#usage)
|
29
|
+
* [Use Cases](#use_cases)
|
30
|
+
* [Announcements](#announcements)
|
31
|
+
* [How to Contribute](#contribute)
|
32
|
+
* [Troubleshooting](#troubleshooting)
|
33
|
+
* [About](#about)
|
34
|
+
* [License](#license)
|
23
35
|
|
24
|
-
|
36
|
+
<a name="installation"></a>
|
37
|
+
# Installation
|
25
38
|
|
26
|
-
|
39
|
+
## Prerequisites
|
27
40
|
|
28
|
-
|
29
|
-
|
41
|
+
- Ruby version >= 2.4 (except version [2.6.0](TROUBLESHOOTING.md#ruby-versions))
|
42
|
+
- The Twilio SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-ruby)
|
30
43
|
|
31
|
-
|
32
|
-
client = SendGrid::Client.new(api_user: 'SENDGRID_USERNAME', api_key: 'SENDGRID_PASSWORD')
|
44
|
+
## Setup Environment Variables
|
33
45
|
|
34
|
-
|
35
|
-
client = SendGrid::Client.new do |c|
|
36
|
-
c.api_user = 'SENDGRID_USERNAME'
|
37
|
-
c.api_key = 'SENDGRID_PASSWORD'
|
38
|
-
end
|
46
|
+
Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:
|
39
47
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
```bash
|
49
|
+
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
|
50
|
+
echo "sendgrid.env" >> .gitignore
|
51
|
+
source ./sendgrid.env
|
44
52
|
```
|
53
|
+
## Install Package
|
45
54
|
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
mail = SendGrid::Mail.new do |m|
|
49
|
-
m.to = 'test@sendgrid.com'
|
50
|
-
m.from = 'taco@cat.limo'
|
51
|
-
m.subject = 'Hello world!'
|
52
|
-
m.text = 'I heard you like pineapple.'
|
53
|
-
end
|
54
|
-
|
55
|
-
res = client.send(mail)
|
56
|
-
puts res.code
|
57
|
-
puts res.body
|
58
|
-
# 200
|
59
|
-
# {"message"=>"success"}
|
60
|
-
```
|
61
|
-
|
62
|
-
You can also create a Mail object with a hash:
|
63
|
-
```ruby
|
64
|
-
res = client.send(SendGrid::Mail.new(to: 'example@example.com', from: 'taco@cat.limo', subject: 'Hello world!', text: 'Hi there!', html: '<b>Hi there!</b>'))
|
65
|
-
puts res.code
|
66
|
-
puts res.body
|
67
|
-
# 200
|
68
|
-
# {"message"=>"success"}
|
69
|
-
```
|
70
|
-
|
71
|
-
#### Attachments
|
55
|
+
Add this line to your application's Gemfile:
|
72
56
|
|
73
|
-
|
74
|
-
|
75
|
-
mail.add_attachment('/tmp/report.pdf', 'july_report.pdf')
|
57
|
+
```bash
|
58
|
+
gem 'sendgrid-ruby'
|
76
59
|
```
|
77
60
|
|
78
|
-
|
61
|
+
And then execute:
|
79
62
|
|
80
|
-
|
81
|
-
|
82
|
-
mail = SendGrid::Mail.new do |m|
|
83
|
-
m.to = 'test@sendgrid.com'
|
84
|
-
m.from = 'taco@cat.limo'
|
85
|
-
m.subject = 'Hello world!'
|
86
|
-
m.text = 'I heard you like the beach.'
|
87
|
-
m.html = 'I heard you like the beach <div><img src="cid:beach"></div>'
|
88
|
-
end
|
89
|
-
mail.add_content('/tmp/beach.jpg', 'beach')
|
90
|
-
result = client.send(mail)
|
63
|
+
```bash
|
64
|
+
bundle
|
91
65
|
```
|
92
66
|
|
93
|
-
|
67
|
+
Or install it yourself using:
|
94
68
|
|
95
|
-
```
|
96
|
-
|
97
|
-
:to,
|
98
|
-
:to_name,
|
99
|
-
:from,
|
100
|
-
:from_name,
|
101
|
-
:subject,
|
102
|
-
:text,
|
103
|
-
:html,
|
104
|
-
:cc,
|
105
|
-
:cc_name,
|
106
|
-
:bcc,
|
107
|
-
:bcc_name,
|
108
|
-
:reply_to,
|
109
|
-
:date,
|
110
|
-
:smtpapi,
|
111
|
-
:attachments,
|
112
|
-
:template
|
113
|
-
}
|
69
|
+
```bash
|
70
|
+
gem install sendgrid-ruby
|
114
71
|
```
|
115
72
|
|
116
|
-
|
73
|
+
## Dependencies
|
117
74
|
|
118
|
-
|
75
|
+
- [Ruby-HTTP-Client](https://github.com/sendgrid/ruby-http-client)
|
119
76
|
|
120
|
-
|
121
|
-
|
122
|
-
m.to = 'rbin@sendgrid.com'
|
123
|
-
m.from = 'taco@rbin.codes'
|
124
|
-
end
|
77
|
+
<a name="quick-start"></a>
|
78
|
+
# Quick Start
|
125
79
|
|
126
|
-
|
127
|
-
````
|
80
|
+
## Hello Email
|
128
81
|
|
129
|
-
|
82
|
+
The following is the minimum needed code to send an email with the [/mail/send Helper](lib/sendgrid/helpers/mail) ([here](examples/helpers/mail/example.rb#L21) is a full example):
|
130
83
|
|
131
|
-
|
132
|
-
|
133
|
-
````ruby
|
134
|
-
mail = SendGrid::Mail.new
|
135
|
-
mail.to = 'taco@rbin.codes'
|
136
|
-
# or
|
137
|
-
mail.to = ['Example Dude <example@email.com>', 'john@email.com']
|
138
|
-
# or
|
139
|
-
mail.to = ['rbin@sendgrid.com', 'taco@cat.limo']
|
140
|
-
````
|
141
|
-
|
142
|
-
#### :from
|
84
|
+
### With Mail Helper Class
|
143
85
|
|
144
86
|
```ruby
|
145
|
-
|
146
|
-
|
147
|
-
```
|
148
|
-
|
149
|
-
#### :cc
|
150
|
-
|
151
|
-
As with **:to**, **:cc** can take a single string or an array of strings.
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
mail = SendGrid::Mail.new
|
155
|
-
mail.cc = ['robin@sendgrid.com', 'taco@cat.limo']
|
156
|
-
```
|
157
|
-
|
158
|
-
#### :bcc
|
159
|
-
|
160
|
-
As with **:to** and **:cc**, **:bcc** can take a single string or an array of strings.
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
mail = SendGrid::Mail.new
|
164
|
-
mail.bcc = ['robin@sendgrid.com', 'taco@cat.limo']
|
165
|
-
```
|
87
|
+
require 'sendgrid-ruby'
|
88
|
+
include SendGrid
|
166
89
|
|
167
|
-
|
90
|
+
from = SendGrid::Email.new(email: 'test@example.com')
|
91
|
+
to = SendGrid::Email.new(email: 'test@example.com')
|
92
|
+
subject = 'Sending with Twilio SendGrid is Fun'
|
93
|
+
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
|
94
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
168
95
|
|
169
|
-
|
170
|
-
|
171
|
-
|
96
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
97
|
+
response = sg.client.mail._('send').post(request_body: mail.to_json)
|
98
|
+
puts response.status_code
|
99
|
+
puts response.body
|
100
|
+
puts response.parsed_body
|
101
|
+
puts response.headers
|
172
102
|
```
|
173
103
|
|
174
|
-
|
175
|
-
#### :text
|
104
|
+
For more complex scenarios, please do not use the above constructor and instead build your own personalization object as [demonstrated here](examples/helpers/mail/example.rb#L21).
|
176
105
|
|
177
|
-
|
106
|
+
### Without Mail Helper Class
|
178
107
|
|
179
|
-
|
180
|
-
mail = SendGrid::Mail.new
|
181
|
-
mail.text = 'WHATTUP KITTY CAT!?'
|
182
|
-
```
|
108
|
+
The following is the minimum needed code to send an email without the /mail/send Helper ([here](examples/mail/mail.rb#L26) is a full example):
|
183
109
|
|
184
|
-
#### :html
|
185
|
-
|
186
|
-
Using the **:html** param allows us to add html content to our email body.
|
187
110
|
```ruby
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
111
|
+
require 'sendgrid-ruby'
|
112
|
+
include SendGrid
|
113
|
+
|
114
|
+
data = JSON.parse('{
|
115
|
+
"personalizations": [
|
116
|
+
{
|
117
|
+
"to": [
|
118
|
+
{
|
119
|
+
"email": "test@example.com"
|
120
|
+
}
|
121
|
+
],
|
122
|
+
"subject": "Sending with Twilio SendGrid is Fun"
|
123
|
+
}
|
124
|
+
],
|
125
|
+
"from": {
|
126
|
+
"email": "test@example.com"
|
127
|
+
},
|
128
|
+
"content": [
|
129
|
+
{
|
130
|
+
"type": "text/plain",
|
131
|
+
"value": "and easy to do anywhere, even with Ruby"
|
132
|
+
}
|
133
|
+
]
|
134
|
+
}')
|
135
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
136
|
+
response = sg.client.mail._("send").post(request_body: data)
|
137
|
+
puts response.status_code
|
138
|
+
puts response.body
|
139
|
+
puts response.parsed_body
|
140
|
+
puts response.headers
|
141
|
+
```
|
142
|
+
|
143
|
+
## General v3 Web API Usage (With Fluent Interface)
|
195
144
|
|
196
145
|
```ruby
|
197
|
-
|
198
|
-
|
146
|
+
require 'sendgrid-ruby'
|
147
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
148
|
+
response = sg.client.suppression.bounces.get()
|
149
|
+
puts response.status_code
|
150
|
+
puts response.body
|
151
|
+
puts response.parsed_body
|
152
|
+
puts response.headers
|
199
153
|
```
|
200
154
|
|
201
|
-
##
|
202
|
-
|
203
|
-
Another easy way to use the [SendGrid Templating](https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/index.html) system is with the `Recipient`, `Mail`, `Template`, and `TemplateMailer` objects.
|
204
|
-
|
205
|
-
Create some `Recipients`
|
155
|
+
## General v3 Web API Usage (Without Fluent Interface)
|
206
156
|
|
207
157
|
```ruby
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
recipient.add_substitution('city', user.city)
|
216
|
-
|
217
|
-
recipients << recipient
|
218
|
-
end
|
158
|
+
require 'sendgrid-ruby'
|
159
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
160
|
+
response = sg.client._("suppression/bounces").get()
|
161
|
+
puts response.status_code
|
162
|
+
puts response.body
|
163
|
+
puts response.parsed_body
|
164
|
+
puts response.headers
|
219
165
|
```
|
220
166
|
|
221
|
-
|
167
|
+
<a name="inbound"></a>
|
168
|
+
# Processing Inbound Email
|
222
169
|
|
223
|
-
|
224
|
-
template = SendGrid::Template.new('MY_TEMPLATE_ID')
|
225
|
-
```
|
226
|
-
|
227
|
-
Create a `Client`
|
170
|
+
Please see [our helper](lib/sendgrid/helpers/inbound) for utilizing our Inbound Parse webhook.
|
228
171
|
|
229
|
-
|
230
|
-
|
231
|
-
```
|
172
|
+
<a name="usage"></a>
|
173
|
+
# Usage
|
232
174
|
|
233
|
-
|
175
|
+
- [Twilio SendGrid Docs](https://sendgrid.com/docs/API_Reference/index.html)
|
176
|
+
- [Library Usage Docs](USAGE.md)
|
177
|
+
- [Example Code](examples)
|
178
|
+
- [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)
|
179
|
+
- [v3 Web API Mail Send Helper](lib/sendgrid/helpers/mail) - build a request object payload for a v3 /mail/send API call.
|
180
|
+
- [Settings Helper](lib/sendgrid/helpers/settings)
|
234
181
|
|
235
|
-
|
236
|
-
|
237
|
-
from: 'admin@email.com',
|
238
|
-
html: '<h1>I like email</h1>',
|
239
|
-
text: 'I like email',
|
240
|
-
subject: 'Email is great',
|
241
|
-
}
|
242
|
-
|
243
|
-
mailer = SendGrid::TemplateMailer.new(client, template, recipients)
|
244
|
-
```
|
182
|
+
<a name="use_cases"></a>
|
183
|
+
# Use Cases
|
245
184
|
|
246
|
-
|
185
|
+
[Examples of common API use cases](use-cases), such as how to send an email with a transactional template.
|
247
186
|
|
248
|
-
|
249
|
-
|
250
|
-
```
|
187
|
+
<a name="announcements"></a>
|
188
|
+
# Announcements
|
251
189
|
|
252
|
-
|
190
|
+
Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-ruby/issues/94). Your support is appreciated!
|
253
191
|
|
254
|
-
|
255
|
-
To utilize the X-SMTPAPI header, we have directly integrated the <a href="https://github.com/SendGridJP/smtpapi-ruby">SendGridJP/smtpapi-ruby</a> gem.
|
256
|
-
For more information, view our <a href=https://sendgrid.com/docs/API_Reference/SMTP_API/index.html>SMTPAPI docs page</a>.
|
257
|
-
</blockquote>
|
192
|
+
All updates to this library are documented in our [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-ruby/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/ruby) for releases and breaking changes.
|
258
193
|
|
259
|
-
|
194
|
+
<a name="contribute"></a>
|
195
|
+
# How to Contribute
|
260
196
|
|
261
|
-
|
262
|
-
header.add_to(['john.doe@example.com', 'jane.doe@example.com'])
|
263
|
-
header.add_substitution('keep', ['secret']) # sub = {keep: ['secret']}
|
264
|
-
header.add_substitution('other', ['one', 'two']) # sub = {keep: ['secret'], other: ['one', 'two']}
|
265
|
-
header.add_unique_arg("unique_code", "8675309")
|
266
|
-
header.add_category("Newsletter")
|
267
|
-
header.add_filter('templates', 'enable', 1) # necessary for each time the template engine is used
|
268
|
-
header.add_filter('templates', 'template_id', '1234-5678-9100-abcd')
|
269
|
-
header.set_ip_pool("marketing_ip_pool")
|
270
|
-
mail.smtpapi = header
|
197
|
+
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.
|
271
198
|
|
272
|
-
|
273
|
-
|
199
|
+
- [Feature Request](CONTRIBUTING.md#feature_request)
|
200
|
+
- [Bug Reports](CONTRIBUTING.md#submit_a_bug_report)
|
201
|
+
- [Improvements to the Codebase](CONTRIBUTING.md#improvements_to_the_codebase)
|
202
|
+
- [Review Pull Requests](CONTRIBUTING.md#code-reviews)
|
274
203
|
|
275
|
-
|
204
|
+
<a name="troubleshooting"></a>
|
205
|
+
# Troubleshooting
|
276
206
|
|
277
|
-
|
207
|
+
Please see our [troubleshooting guide](TROUBLESHOOTING.md) for common library issues.
|
278
208
|
|
279
|
-
|
280
|
-
|
281
|
-
3. Update CHANGELOG.md
|
282
|
-
4. Commit Version bump vX.X.X
|
283
|
-
5. `rake release`
|
284
|
-
6. Push changes to GitHub
|
285
|
-
7. Release tag on GitHub vX.X.X
|
209
|
+
<a name="about"></a>
|
210
|
+
# About
|
286
211
|
|
287
|
-
|
212
|
+
sendgrid-ruby is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-ruby are trademarks of Twilio SendGrid, Inc.
|
288
213
|
|
289
|
-
|
290
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
291
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
292
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
293
|
-
5. Create a new Pull Request
|
214
|
+
If you need help installing or using the library, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).
|
294
215
|
|
295
|
-
|
216
|
+
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
|
296
217
|
|
218
|
+
<a name="license"></a>
|
219
|
+
# License
|
220
|
+
[The MIT License (MIT)](LICENSE)
|
data/Rakefile
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
require 'rake/testtask'
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'rspec/core/rake_task'
|
3
4
|
|
4
|
-
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.test_files = FileList['test/sendgrid/test*.rb', 'test/sendgrid/helpers/mail/test*.rb', 'test/sendgrid/helpers/permissions/test*.rb']
|
8
|
+
t.verbose = true
|
9
|
+
end
|
5
10
|
|
6
|
-
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
12
|
|
8
|
-
|
13
|
+
desc 'Run tests'
|
14
|
+
task default: %i[spec test]
|
data/TROUBLESHOOTING.md
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
If you have an issue logging into your Twilio SendGrid account, please read this [document](https://sendgrid.com/docs/ui/account-and-settings/troubleshooting-login/). For any questions regarding login issues, please contact our [support team](https://support.sendgrid.com).
|
2
|
+
|
3
|
+
If you have a non-library Twilio SendGrid issue, please contact our [support team](https://support.sendgrid.com).
|
4
|
+
|
5
|
+
If you can't find a solution below, please open an [issue](https://github.com/sendgrid/sendgrid-ruby/issues).
|
6
|
+
|
7
|
+
|
8
|
+
## Table of Contents
|
9
|
+
|
10
|
+
* [Migrating from v2 to v3](#migrating-from-v2-to-v3)
|
11
|
+
* [Continue Using v2](#continue-using-v2)
|
12
|
+
* [Testing v3 /mail/send Calls Directly](#testing-v3-mailsend-calls-directly)
|
13
|
+
* [Error Messages](#error-messages)
|
14
|
+
* [Versioning](#versioning)
|
15
|
+
* [Environment Variables and Your Twilio SendGrid API Key](#environment-variables-and-your-twilio-sendgrid-api-key)
|
16
|
+
* [Using the Package Manager](#using-the-package-manager)
|
17
|
+
* [Rails Specifics](#rails-specifics)
|
18
|
+
* [Ruby Versions](#ruby-versions)
|
19
|
+
* [Viewing the Request Body](#viewing-the-request-body)
|
20
|
+
* [Verifying Event Webhooks](#signed-webhooks)
|
21
|
+
|
22
|
+
<a name="migrating"></a>
|
23
|
+
## Migrating from v2 to v3
|
24
|
+
|
25
|
+
Please review [our guide](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) on how to migrate from v2 to v3.
|
26
|
+
|
27
|
+
<a name="v2"></a>
|
28
|
+
## Continue Using v2
|
29
|
+
|
30
|
+
[Here](https://github.com/sendgrid/sendgrid-ruby/tree/0fbf579c0f7ed1dff87adc4957c4dc5a6b257068) is the last working version with v2 support.
|
31
|
+
|
32
|
+
Using RubyGems:
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
gem 'sendgrid-ruby', '1.1.6'
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
bundle
|
44
|
+
```
|
45
|
+
|
46
|
+
Or install it yourself using:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
gem install sendgrid-ruby -v 1.1.6
|
50
|
+
```
|
51
|
+
|
52
|
+
Download:
|
53
|
+
|
54
|
+
Click the "Clone or download" green button in [GitHub](https://github.com/sendgrid/sendgrid-ruby/tree/0fbf579c0f7ed1dff87adc4957c4dc5a6b257068) and choose download.
|
55
|
+
|
56
|
+
<a name="testing"></a>
|
57
|
+
## Testing v3 /mail/send Calls Directly
|
58
|
+
|
59
|
+
[Here](https://sendgrid.com/docs/for-developers/sending-email/curl-examples/) are some cURL examples for common use cases.
|
60
|
+
|
61
|
+
<a name="error"></a>
|
62
|
+
## Error Messages
|
63
|
+
|
64
|
+
To read the error message returned by SendGrid's API:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
begin
|
68
|
+
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
69
|
+
rescue Exception => e
|
70
|
+
puts e.message
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
<a name="versioning"></a>
|
75
|
+
## Versioning
|
76
|
+
|
77
|
+
We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with your code and never auto-update to the latest version. Especially when there is a MAJOR point release since that is guaranteed to be a breaking change. Changes are documented in the [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-ruby/releases) section.
|
78
|
+
|
79
|
+
<a name="environment"></a>
|
80
|
+
## Environment Variables and Your Twilio SendGrid API Key
|
81
|
+
|
82
|
+
All of our examples assume you are using [environment variables](https://github.com/sendgrid/sendgrid-ruby#setup-environment-variables) to hold your Twilio SendGrid API key.
|
83
|
+
|
84
|
+
If you choose to add your Twilio SendGrid API key directly (not recommended):
|
85
|
+
|
86
|
+
`sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])`
|
87
|
+
|
88
|
+
becomes
|
89
|
+
|
90
|
+
`sg = SendGrid::API.new(api_key: 'SENDGRID_API_KEY')`
|
91
|
+
|
92
|
+
In the first case, SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual Twilio SendGrid API Key.
|
93
|
+
|
94
|
+
<a name="package-manager"></a>
|
95
|
+
## Using the Package Manager
|
96
|
+
|
97
|
+
We upload this library to [RubyGems](https://rubygems.org/gems/sendgrid-ruby) whenever we make a release. This allows you to use [RubyGems](https://rubygems.org) for easy installation.
|
98
|
+
|
99
|
+
In most cases we recommend you download the latest version of the library, but if you need a different version, please use:
|
100
|
+
|
101
|
+
Add this line to your application's Gemfile:
|
102
|
+
|
103
|
+
```bash
|
104
|
+
gem 'sendgrid-ruby', 'X.X.X'
|
105
|
+
```
|
106
|
+
|
107
|
+
And then execute:
|
108
|
+
|
109
|
+
```bash
|
110
|
+
bundle
|
111
|
+
```
|
112
|
+
|
113
|
+
Or install it yourself using:
|
114
|
+
|
115
|
+
```bash
|
116
|
+
gem install sendgrid-ruby -v X.X.X
|
117
|
+
```
|
118
|
+
|
119
|
+
<a name="rails-specifics"></a>
|
120
|
+
## Rails Specifics
|
121
|
+
|
122
|
+
- Namespace collision between Rails own `Mail` class and sendgrid class `Mail`. To avoid that issues please use `SendGrid:: Mail` instead.
|
123
|
+
|
124
|
+
- The possibility of a namespace collision between the sendgrid class `Email` and your own defined `Email` class. To avoid these issues, you can skip the `include SendGrid` line and use the `SendGrid::` prefix for Email. Please see this [SO answer](https://stackoverflow.com/questions/41508464/rails-model-name-conflict-with-included-gem?noredirect=1#comment70223099_41508464) for specifics.
|
125
|
+
|
126
|
+
<a name="ruby-versions"></a>
|
127
|
+
## Ruby Versions
|
128
|
+
|
129
|
+
This SDK [does not work with ruby version 2.6.0](https://github.com/sendgrid/sendgrid-ruby/issues/378) because of [this bug](https://bugs.ruby-lang.org/issues/15468). Please use any other [supported version](https://github.com/sendgrid/sendgrid-ruby#prerequisites).
|
130
|
+
|
131
|
+
<a name="request-body"></a>
|
132
|
+
## Viewing the Request Body
|
133
|
+
|
134
|
+
When debugging or testing, it may be useful to examine the raw request header to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
|
135
|
+
|
136
|
+
You can do this before `response = sg.client.mail._('send').post(request_body: mail.to_json)` like so:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
puts mail.to_json
|
140
|
+
```
|
141
|
+
|
142
|
+
<a name="signed-webhooks"></a>
|
143
|
+
## Signed Webhook Verification
|
144
|
+
|
145
|
+
Twilio SendGrid's Event Webhook will notify a URL via HTTP POST with information about events that occur as your mail is processed. [This](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features) article covers all you need to know to secure the Event Webhook, allowing you to verify that incoming requests originate from Twilio SendGrid. The sendgrid-ruby library can help you verify these Signed Event Webhooks.
|
146
|
+
|
147
|
+
You can find the usage example [here](examples/helpers/eventwebhook/example.rb) and the tests [here](spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb).
|
148
|
+
If you are still having trouble getting the validation to work, follow the following instructions:
|
149
|
+
- Be sure to use the *raw* payload for validation
|
150
|
+
- Be sure to include a trailing carriage return and newline in your payload
|
151
|
+
- In case of multi-event webhooks, make sure you include the trailing newline and carriage return after *each* event
|