sendgrid-actionmailer 3.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/CHANGELOG.md +33 -2
- data/README.md +41 -23
- data/lib/sendgrid_actionmailer.rb +37 -26
- data/lib/sendgrid_actionmailer/railtie.rb +3 -1
- data/lib/sendgrid_actionmailer/version.rb +1 -1
- data/sendgrid-actionmailer.gemspec +1 -1
- data/spec/lib/sendgrid_actionmailer_spec.rb +68 -3
- metadata +8 -8
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb577847afaccad306f73fa0c34b928298b8dda4de873f8d0459dd96f41bee34
|
4
|
+
data.tar.gz: 9e9fa4dc9d9301aa0473f90ce3c1ae683a91d4313945333c636fc302dcb0f624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f387f4d44937198fcbbad709ec316b27d0e8bbbbd87b997fbeb5fdb5ec6a26a8f1b72f226bbae55b6e23692711b6dabcce9ea6aa240c7789a55ca776a7761cdf
|
7
|
+
data.tar.gz: 309ea7246ece21e445746f2faab91ad30b6f37392da0db1c00ec51e4033362cee300b86e546ee2c6e6cd18d4b2012454fa50d2fee31d43dcf1f9b6ee50b5062f
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 3.2.0 - 2020-02-16
|
4
|
+
- #107 Feature/sendgrid api settings, expand settings/options to allow for other SendGrid::Api client settings
|
5
|
+
- #106 The SendGrid API simple error handling
|
6
|
+
- #105 Github Actions CI
|
7
|
+
- #102 Add http_options to configurable in mailer settings
|
8
|
+
- #101 Railtie should use ActiveSupport.on_load
|
9
|
+
|
10
|
+
## 3.1.1 - 2020-11-06
|
11
|
+
- #92 globally configured mail_settings
|
12
|
+
- #95 add_mail_settings - support global settings
|
13
|
+
|
14
|
+
## 3.1.0 - 2020-8-03
|
15
|
+
|
16
|
+
### Changes
|
17
|
+
|
18
|
+
- #81 Fix warnings with ruby 2.7
|
19
|
+
- #83 Allow string type mail.to
|
20
|
+
- #84 Content-ID values to fix inline attachments
|
21
|
+
|
22
|
+
## 3.0.2 - 2020-4-20
|
23
|
+
|
24
|
+
### Changes
|
25
|
+
|
26
|
+
- perform_send_request setting for testing perposes
|
27
|
+
|
28
|
+
## 3.0.1 - 2020-4-3
|
29
|
+
|
30
|
+
### Changes
|
31
|
+
|
32
|
+
- Validate error response body for empty string
|
33
|
+
|
3
34
|
## 3.0.0 - 2020-3-2
|
4
35
|
|
5
36
|
### Removed
|
@@ -8,13 +39,13 @@
|
|
8
39
|
|
9
40
|
## 2.6.0 - 2020-1-23
|
10
41
|
|
11
|
-
###
|
42
|
+
### Changes
|
12
43
|
|
13
44
|
- Dont send content types with dynamic templates (#69)
|
14
45
|
|
15
46
|
## 2.5.0 - 2020-1-21
|
16
47
|
|
17
|
-
###
|
48
|
+
### Changes
|
18
49
|
|
19
50
|
- Add personalizations field (#60)
|
20
51
|
|
data/README.md
CHANGED
@@ -24,6 +24,18 @@ Normal ActionMailer usage will now transparently be sent using SendGrid's Web AP
|
|
24
24
|
|
25
25
|
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body')```
|
26
26
|
|
27
|
+
### Mail Settings
|
28
|
+
|
29
|
+
Mail settings, such as sandbox_mode, may be applied globally through the sendgrid_actionmailer_settings configuration.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
config.action_mailer.delivery_method = :sendgrid_actionmailer
|
33
|
+
config.action_mailer.sendgrid_actionmailer_settings = {
|
34
|
+
api_key: ENV['SENDGRID_API_KEY'],
|
35
|
+
mail_settings: { sandbox_mode: { enable: true }}
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
27
39
|
### Dynamic API Key
|
28
40
|
|
29
41
|
If you need to send mail for a number of Sendgrid accounts, you can set the API key for these as follows:
|
@@ -31,11 +43,12 @@ If you need to send mail for a number of Sendgrid accounts, you can set the API
|
|
31
43
|
|
32
44
|
```ruby
|
33
45
|
mail(to: 'example@email.com',
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
46
|
+
subject: 'email subject',
|
47
|
+
body: 'email body',
|
48
|
+
delivery_method_options: {
|
49
|
+
api_key: 'SENDGRID_API_KEY'
|
50
|
+
}
|
51
|
+
)
|
39
52
|
```
|
40
53
|
|
41
54
|
## SendGrid Mail Extensions
|
@@ -86,7 +99,7 @@ The unsubscribe group to associate with this email.
|
|
86
99
|
#### groups_to_display (array[integer])
|
87
100
|
An array containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page.
|
88
101
|
|
89
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', asm: group_id: 99, groups_to_display: [4,5,6,7,8])```
|
102
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', asm: { group_id: 99, groups_to_display: [4,5,6,7,8] })```
|
90
103
|
|
91
104
|
### ip_pool_name (string)
|
92
105
|
The IP Pool that you would like to send this email from.
|
@@ -105,7 +118,7 @@ Indicates if this setting is enabled.
|
|
105
118
|
##### email (string)
|
106
119
|
The email address that you would like to receive the BCC.
|
107
120
|
|
108
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', mail_settings: {bcc: {enable: true, email: 'bcc@example.com}})```
|
121
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', mail_settings: { bcc: { enable: true, email: 'bcc@example.com }})```
|
109
122
|
|
110
123
|
#### bypass_list_management (object)
|
111
124
|
Allows you to bypass all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient. This should only be used in emergencies when it is absolutely necessary that every recipient receives your email.
|
@@ -113,7 +126,7 @@ Allows you to bypass all unsubscribe groups and suppressions to ensure that the
|
|
113
126
|
###### enable (boolean)
|
114
127
|
Indicates if this setting is enabled.
|
115
128
|
|
116
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
129
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', mail_settings: { bypass_list_management: { enable: true }})```
|
117
130
|
|
118
131
|
#### footer (object)
|
119
132
|
The default footer that you would like included on every email.
|
@@ -127,7 +140,7 @@ The plain text content of your footer.
|
|
127
140
|
##### html (string)
|
128
141
|
The HTML content of your footer.
|
129
142
|
|
130
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
143
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', mail_settings: { footer: { enable: true, text: 'FOOTER', html: '<h1>FOOTER</h1>' }})```
|
131
144
|
|
132
145
|
#### sandbox_mode (object)
|
133
146
|
This allows you to send a test email to ensure that your request body is valid and formatted correctly.
|
@@ -135,7 +148,7 @@ This allows you to send a test email to ensure that your request body is valid a
|
|
135
148
|
##### enable (boolean)
|
136
149
|
Indicates if this setting is enabled.
|
137
150
|
|
138
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
151
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', mail_settings: { sandbox_mode: { enable: true }})```
|
139
152
|
|
140
153
|
#### spam_check (object)
|
141
154
|
This allows you to test the content of your email for spam.
|
@@ -149,7 +162,8 @@ The threshold used to determine if your content qualifies as spam on a scale fro
|
|
149
162
|
##### post_to_url (string)
|
150
163
|
An Inbound Parse URL that you would like a copy of your email along with the spam report to be sent to.
|
151
164
|
|
152
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
165
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', mail_settings: { spam_check: { enable: true, threshold: 1, post_to_url: 'https://spamcatcher.sendgrid.com' }})```
|
166
|
+
|
153
167
|
### tracking_settings(json)
|
154
168
|
Settings to determine how you would like to track the metrics of how your recipients interact with your email.
|
155
169
|
|
@@ -159,10 +173,10 @@ Allows you to track whether a recipient clicked a link in your email.
|
|
159
173
|
##### enable (boolean)
|
160
174
|
Indicates if this setting is enabled.
|
161
175
|
|
162
|
-
#####
|
176
|
+
##### enable_text (boolean)
|
163
177
|
Indicates if this setting should be included in the text/plain portion of your email.
|
164
178
|
|
165
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
179
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', tracking_settings: { click_tracking: { enable: false, enable_text: false }})```
|
166
180
|
|
167
181
|
#### open_tracking (object)
|
168
182
|
Allows you to track whether the email was opened or not, but including a single pixel image in the body of the content. When the pixel is loaded, we can log that the email was opened.
|
@@ -173,7 +187,7 @@ Indicates if this setting is enabled.
|
|
173
187
|
##### substitution_tag (string)
|
174
188
|
Allows you to specify a substitution tag that you can insert in the body of your email at a location that you desire. This tag will be replaced by the open tracking pixel.
|
175
189
|
|
176
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
190
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', tracking_settings: { open_tracking: { enable: true, substitution_tag: 'Optional tag to replace with the open image in the body of the message' }})```
|
177
191
|
|
178
192
|
#### subscription_tracking (object)
|
179
193
|
Allows you to insert a subscription management link at the bottom of the text and html bodies of your email. If you would like to specify the location of the link within your email, you may use the substitution_tag.
|
@@ -190,7 +204,7 @@ HTML to be appended to the email, with the subscription tracking link. You may c
|
|
190
204
|
##### substitution_tag (string)
|
191
205
|
A tag that will be replaced with the unsubscribe URL. for example: [unsubscribe_url]. If this parameter is used, it will override both the text and html parameters. The URL of the link will be placed at the substitution tag’s location, with no additional formatting.
|
192
206
|
|
193
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
207
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', tracking_settings: { subscription_tracking: { enable: true, text: 'text to insert into the text/plain portion of the message', html: 'html to insert into the text/html portion of the message', substitution_tag: 'Optional tag to replace with the open image in the body of the message' }})```
|
194
208
|
|
195
209
|
#### ganalytics (object)
|
196
210
|
Allows you to enable tracking provided by Google Analytics.
|
@@ -213,13 +227,13 @@ Used to differentiate your campaign from advertisements.
|
|
213
227
|
##### utm_campaign (string)
|
214
228
|
The name of the campaign.
|
215
229
|
|
216
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
230
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', tracking_settings: { ganalytics: { enable: true, utm_source: 'some source', utm_medium: 'some medium', utm_term: 'some term', utm_content: 'some content', utm_campaign: 'some campaign' }})```
|
217
231
|
|
218
232
|
### dynamic_template_data (json)
|
219
233
|
|
220
|
-
Data to provide for feeding the new dynamic templates in Sendgrid with valueable data. This also disables the following Unsubscribe links because of deprecation of substitutions in the new template implementaiton.
|
234
|
+
Data to provide for feeding the new dynamic templates in Sendgrid with valueable data. This also disables the following Unsubscribe links because of deprecation of substitutions in the new template implementaiton. Variables are available within templates using [{{handlebar syntax}}](https://sendgrid.com/docs/for-developers/sending-email/using-handlebars).
|
221
235
|
|
222
|
-
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body',
|
236
|
+
```mail(to: 'example@email.com', subject: 'email subject', body: 'email body', dynamic_template_data: { variable_1: 'foo', variable_2: 'bar' })```
|
223
237
|
|
224
238
|
### personalizations (json)
|
225
239
|
|
@@ -246,19 +260,23 @@ Example usage:
|
|
246
260
|
|
247
261
|
```
|
248
262
|
mail(subject: 'default subject', 'email body', personalizations: [
|
249
|
-
{ to: { email: 'example@example.com' }},
|
250
|
-
{ to: { email: 'example2@example.com' }}
|
263
|
+
{ to: [{ email: 'example@example.com' }]},
|
264
|
+
{ to: [{ email: 'example2@example.com' }]}
|
251
265
|
])
|
252
|
-
|
253
266
|
```
|
254
267
|
|
255
|
-
|
256
268
|
### Unsubscribe Links
|
257
269
|
|
258
|
-
Sendgrid unfortunately uses <% %> for their default substitution syntax, which makes it incompatible with Rails templates. Their proposed solution is to use Personalization Substitutions with the v3 Mail Send Endpoint.
|
270
|
+
Sendgrid unfortunately uses <% %> for their default substitution syntax, which makes it incompatible with Rails templates. Their proposed solution is to use Personalization Substitutions with the v3 Mail Send Endpoint. This gem makes that modification to make the following Rails friendly unsubscribe urls.
|
259
271
|
|
260
272
|
* `<a href="%asm_group_unsubscribe_raw_url%">Unsubscribe</a>`
|
261
273
|
* `<a href="%asm_global_unsubscribe_raw_url%">Unsubscribe from List</a>`
|
262
274
|
* `<a href="%asm_preferences_raw_url%">Manage Email Preferences</a>`
|
263
275
|
|
264
276
|
Note: This feature, and substitutions in general, do not work in combination with dynamic templates.
|
277
|
+
|
278
|
+
## Testing
|
279
|
+
|
280
|
+
The setting `perform_send_request` is available to disable sending for testing purposes. Setting perform_send_request false and return_response true enables the testing of the JSON API payload.
|
281
|
+
|
282
|
+
|
@@ -14,13 +14,14 @@ module SendGridActionMailer
|
|
14
14
|
raise_delivery_errors: false
|
15
15
|
}.freeze
|
16
16
|
|
17
|
-
attr_accessor :settings, :
|
17
|
+
attr_accessor :settings, :options
|
18
18
|
|
19
|
-
def initialize(
|
19
|
+
def initialize(params = {})
|
20
20
|
self.settings = DEFAULTS.merge(params)
|
21
21
|
end
|
22
22
|
|
23
23
|
def deliver!(mail)
|
24
|
+
self.options = {}
|
24
25
|
sendgrid_mail = Mail.new.tap do |m|
|
25
26
|
m.from = to_email(mail.from)
|
26
27
|
m.reply_to = to_email(mail.reply_to)
|
@@ -28,21 +29,31 @@ module SendGridActionMailer
|
|
28
29
|
end
|
29
30
|
|
30
31
|
add_personalizations(sendgrid_mail, mail)
|
31
|
-
|
32
|
+
add_options(sendgrid_mail, mail)
|
32
33
|
add_content(sendgrid_mail, mail)
|
33
34
|
add_send_options(sendgrid_mail, mail)
|
34
35
|
add_mail_settings(sendgrid_mail, mail)
|
35
36
|
add_tracking_settings(sendgrid_mail, mail)
|
36
37
|
|
37
|
-
|
38
|
+
if (settings[:perform_send_request] == false)
|
39
|
+
response = sendgrid_mail
|
40
|
+
else
|
41
|
+
response = perform_send_request(sendgrid_mail)
|
42
|
+
end
|
38
43
|
|
39
44
|
settings[:return_response] ? response : self
|
40
45
|
end
|
41
46
|
|
42
47
|
private
|
43
48
|
|
49
|
+
def client_options
|
50
|
+
options.dup
|
51
|
+
.select { |key, value| key.to_s.match(/(api_key|host|request_headers|version|impersonate_subuser)/) }
|
52
|
+
.merge(http_options: settings.fetch(:http_options, {}))
|
53
|
+
end
|
54
|
+
|
44
55
|
def client
|
45
|
-
@client = SendGrid::API.new(
|
56
|
+
@client = SendGrid::API.new(**client_options).client
|
46
57
|
end
|
47
58
|
|
48
59
|
# type should be either :plain or :html
|
@@ -131,7 +142,7 @@ module SendGridActionMailer
|
|
131
142
|
a.disposition = disposition unless disposition.nil?
|
132
143
|
|
133
144
|
has_content_id = part.header && part.has_content_id?
|
134
|
-
a.content_id = part.header['content_id'].
|
145
|
+
a.content_id = part.header['content_id'].field.content_id if has_content_id
|
135
146
|
end
|
136
147
|
end
|
137
148
|
|
@@ -142,10 +153,10 @@ module SendGridActionMailer
|
|
142
153
|
content_disp.disposition_type
|
143
154
|
end
|
144
155
|
|
145
|
-
def
|
146
|
-
self.
|
147
|
-
if mail['delivery-method-options']
|
148
|
-
self.
|
156
|
+
def add_options(sendgrid_mail, mail)
|
157
|
+
self.options.merge!(**self.class.transform_keys(self.settings, &:to_sym))
|
158
|
+
if !!(mail['delivery-method-options'])
|
159
|
+
self.options.merge!(**self.class.transform_keys(mail['delivery-method-options'].unparsed_value , &:to_sym))
|
149
160
|
end
|
150
161
|
end
|
151
162
|
|
@@ -181,7 +192,7 @@ module SendGridActionMailer
|
|
181
192
|
sendgrid_mail.add_personalization(setup_personalization(mail, p))
|
182
193
|
end
|
183
194
|
end
|
184
|
-
if (mail.to && mail.to.
|
195
|
+
if (mail.to && !mail.to.empty?) || (mail.cc && !mail.cc.empty?) || (mail.bcc && !mail.bcc.empty?)
|
185
196
|
personalization = setup_personalization(mail, {})
|
186
197
|
to_emails(mail.to).each { |to| personalization.add_to(to) }
|
187
198
|
to_emails(mail.cc).each { |cc| personalization.add_cc(cc) }
|
@@ -225,7 +236,7 @@ module SendGridActionMailer
|
|
225
236
|
asm = asm.delete_if { |key, value|
|
226
237
|
!key.to_s.match(/(group_id)|(groups_to_display)/) }
|
227
238
|
if asm.keys.map(&:to_s).include?('group_id')
|
228
|
-
sendgrid_mail.asm = ASM.new(asm)
|
239
|
+
sendgrid_mail.asm = ASM.new(**self.class.transform_keys(asm, &:to_sym))
|
229
240
|
end
|
230
241
|
end
|
231
242
|
if mail['ip_pool_name']
|
@@ -234,23 +245,25 @@ module SendGridActionMailer
|
|
234
245
|
end
|
235
246
|
|
236
247
|
def add_mail_settings(sendgrid_mail, mail)
|
237
|
-
|
238
|
-
|
248
|
+
local_settings = mail['mail_settings'] && mail['mail_settings'].unparsed_value || {}
|
249
|
+
global_settings = self.settings[:mail_settings] || {}
|
250
|
+
settings = global_settings.merge(local_settings)
|
251
|
+
unless settings.empty?
|
239
252
|
sendgrid_mail.mail_settings = MailSettings.new.tap do |m|
|
240
253
|
if settings[:bcc]
|
241
|
-
m.bcc = BccSettings.new(settings[:bcc])
|
254
|
+
m.bcc = BccSettings.new(**settings[:bcc])
|
242
255
|
end
|
243
256
|
if settings[:bypass_list_management]
|
244
|
-
m.bypass_list_management = BypassListManagement.new(settings[:bypass_list_management])
|
257
|
+
m.bypass_list_management = BypassListManagement.new(**settings[:bypass_list_management])
|
245
258
|
end
|
246
259
|
if settings[:footer]
|
247
|
-
m.footer = Footer.new(settings[:footer])
|
260
|
+
m.footer = Footer.new(**settings[:footer])
|
248
261
|
end
|
249
262
|
if settings[:sandbox_mode]
|
250
|
-
m.sandbox_mode = SandBoxMode.new(settings[:sandbox_mode])
|
263
|
+
m.sandbox_mode = SandBoxMode.new(**settings[:sandbox_mode])
|
251
264
|
end
|
252
265
|
if settings[:spam_check]
|
253
|
-
m.spam_check = SpamCheck.new(settings[:spam_check])
|
266
|
+
m.spam_check = SpamCheck.new(**settings[:spam_check])
|
254
267
|
end
|
255
268
|
end
|
256
269
|
end
|
@@ -261,16 +274,16 @@ module SendGridActionMailer
|
|
261
274
|
settings = mail['tracking_settings'].unparsed_value
|
262
275
|
sendgrid_mail.tracking_settings = TrackingSettings.new.tap do |t|
|
263
276
|
if settings[:click_tracking]
|
264
|
-
t.click_tracking = ClickTracking.new(settings[:click_tracking])
|
277
|
+
t.click_tracking = ClickTracking.new(**settings[:click_tracking])
|
265
278
|
end
|
266
279
|
if settings[:open_tracking]
|
267
|
-
t.open_tracking = OpenTracking.new(settings[:open_tracking])
|
280
|
+
t.open_tracking = OpenTracking.new(**settings[:open_tracking])
|
268
281
|
end
|
269
282
|
if settings[:subscription_tracking]
|
270
|
-
t.subscription_tracking = SubscriptionTracking.new(settings[:subscription_tracking])
|
283
|
+
t.subscription_tracking = SubscriptionTracking.new(**settings[:subscription_tracking])
|
271
284
|
end
|
272
285
|
if settings[:ganalytics]
|
273
|
-
t.ganalytics = Ganalytics.new(settings[:ganalytics])
|
286
|
+
t.ganalytics = Ganalytics.new(**settings[:ganalytics])
|
274
287
|
end
|
275
288
|
end
|
276
289
|
end
|
@@ -280,9 +293,7 @@ module SendGridActionMailer
|
|
280
293
|
result = client.mail._('send').post(request_body: email.to_json) # ლ(ಠ益ಠლ) that API
|
281
294
|
|
282
295
|
if result.status_code && result.status_code.start_with?('4')
|
283
|
-
|
284
|
-
full_message = "Sendgrid delivery failed with #{result.status_code} #{message}"
|
285
|
-
|
296
|
+
full_message = "Sendgrid delivery failed with #{result.status_code}: #{result.body}"
|
286
297
|
settings[:raise_delivery_errors] ? raise(SendgridDeliveryError, full_message) : warn(full_message)
|
287
298
|
end
|
288
299
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module SendGridActionMailer
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
initializer 'sendgrid_actionmailer.add_delivery_method', before: 'action_mailer.set_configs' do
|
4
|
-
|
4
|
+
ActiveSupport.on_load(:action_mailer) do
|
5
|
+
ActionMailer::Base.add_delivery_method(:sendgrid_actionmailer, SendGridActionMailer::DeliveryMethod)
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.add_dependency 'mail', '~> 2.7'
|
23
|
-
spec.add_dependency 'sendgrid-ruby', '~> 6.
|
23
|
+
spec.add_dependency 'sendgrid-ruby', '~> 6.4'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'appraisal', '~> 2.1.0'
|
26
26
|
spec.add_development_dependency 'bundler'
|
@@ -40,6 +40,11 @@ module SendGridActionMailer
|
|
40
40
|
expect(m.settings[:api_key]).to eq('ABCDEFG')
|
41
41
|
end
|
42
42
|
|
43
|
+
it 'has correct host' do
|
44
|
+
m = DeliveryMethod.new(host: 'example.com')
|
45
|
+
expect(m.settings[:host]).to eq('example.com')
|
46
|
+
end
|
47
|
+
|
43
48
|
it 'default raise_delivery_errors' do
|
44
49
|
m = DeliveryMethod.new()
|
45
50
|
expect(m.settings[:raise_delivery_errors]).to eq(false)
|
@@ -59,6 +64,16 @@ module SendGridActionMailer
|
|
59
64
|
m = DeliveryMethod.new(return_response: true)
|
60
65
|
expect(m.settings[:return_response]).to eq(true)
|
61
66
|
end
|
67
|
+
|
68
|
+
it 'sets perform_deliveries' do
|
69
|
+
m = DeliveryMethod.new(perform_send_request: false)
|
70
|
+
expect(m.settings[:perform_send_request]).to eq(false)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'sets http_options' do
|
74
|
+
m = DeliveryMethod.new(http_options: {open_timeout: 40})
|
75
|
+
expect(m.settings[:http_options]).to eq({open_timeout: 40})
|
76
|
+
end
|
62
77
|
end
|
63
78
|
|
64
79
|
describe '#deliver!' do
|
@@ -101,11 +116,11 @@ module SendGridActionMailer
|
|
101
116
|
end
|
102
117
|
|
103
118
|
it 'sets dynamic api_key, but should revert to default settings api_key' do
|
104
|
-
expect(SendGrid::API).to receive(:new).with(api_key: 'key')
|
119
|
+
expect(SendGrid::API).to receive(:new).with(api_key: 'key', http_options: {})
|
105
120
|
mailer.deliver!(default)
|
106
|
-
expect(SendGrid::API).to receive(:new).with(api_key: 'test_key')
|
121
|
+
expect(SendGrid::API).to receive(:new).with(api_key: 'test_key', http_options: {})
|
107
122
|
mailer.deliver!(mail)
|
108
|
-
expect(SendGrid::API).to receive(:new).with(api_key: 'key')
|
123
|
+
expect(SendGrid::API).to receive(:new).with(api_key: 'key', http_options: {})
|
109
124
|
mailer.deliver!(default)
|
110
125
|
end
|
111
126
|
end
|
@@ -549,6 +564,9 @@ module SendGridActionMailer
|
|
549
564
|
expect(content['filename']).to eq('specs.rb')
|
550
565
|
expect(content['type']).to eq('application/x-ruby')
|
551
566
|
expect(content['content_id'].class).to eq(String)
|
567
|
+
expect(content['content_id']).to include("@")
|
568
|
+
expect(content['content_id']).not_to include("<")
|
569
|
+
expect(content['content_id']).not_to include(">")
|
552
570
|
end
|
553
571
|
end
|
554
572
|
|
@@ -756,6 +774,53 @@ module SendGridActionMailer
|
|
756
774
|
expect(client.sent_mail['personalizations'][2]['bcc']).to eq([{"email"=>"test@sendgrid.com"}])
|
757
775
|
end
|
758
776
|
end
|
777
|
+
|
778
|
+
context 'when perform_send_request false' do
|
779
|
+
it 'should not send and email and return json body' do
|
780
|
+
m = DeliveryMethod.new(perform_send_request: false, return_response: true, api_key: 'key')
|
781
|
+
response = m.deliver!(mail)
|
782
|
+
expect(response).to respond_to(:to_json)
|
783
|
+
end
|
784
|
+
end
|
785
|
+
|
786
|
+
context 'when mail_settings are present' do
|
787
|
+
it 'should apply mail_settings to request body' do
|
788
|
+
m = DeliveryMethod.new(api_key: 'key', return_response: true, mail_settings: { sandbox_mode: {enable: true }})
|
789
|
+
m.deliver!(mail)
|
790
|
+
expect(client.sent_mail['mail_settings']).to eq("sandbox_mode" => {"enable" => true })
|
791
|
+
end
|
792
|
+
|
793
|
+
context 'when mail has mail_settings set' do
|
794
|
+
before { mail['mail_settings'] = { spam_check: { enable: true } } }
|
795
|
+
|
796
|
+
it 'should combine local mail_settings with global settings' do
|
797
|
+
m = DeliveryMethod.new(api_key: 'key', return_response: true, mail_settings: { sandbox_mode: {enable: true }})
|
798
|
+
m.deliver!(mail)
|
799
|
+
expect(client.sent_mail['mail_settings']).to eq(
|
800
|
+
"sandbox_mode" => {"enable" => true },
|
801
|
+
"spam_check" => {"enable" => true },
|
802
|
+
)
|
803
|
+
end
|
804
|
+
end
|
805
|
+
|
806
|
+
context 'when mail contains the same setting as global settings' do
|
807
|
+
before do
|
808
|
+
mail['mail_settings'] = {
|
809
|
+
sandbox_mode: { enable: false },
|
810
|
+
spam_check: { enable: true }
|
811
|
+
}
|
812
|
+
end
|
813
|
+
|
814
|
+
it 'should apply local mail_settings on top of global settings' do
|
815
|
+
m = DeliveryMethod.new(api_key: 'key', return_response: true, mail_settings: { sandbox_mode: {enable: true }})
|
816
|
+
m.deliver!(mail)
|
817
|
+
expect(client.sent_mail['mail_settings']).to eq(
|
818
|
+
"sandbox_mode" => {"enable" => false },
|
819
|
+
"spam_check" => {"enable" => true },
|
820
|
+
)
|
821
|
+
end
|
822
|
+
end
|
823
|
+
end
|
759
824
|
end
|
760
825
|
end
|
761
826
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-actionmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eddie Zaneski
|
8
8
|
- Kristján Pétursson
|
9
9
|
- Nick Muerdter
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mail
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '6.
|
35
|
+
version: '6.4'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '6.
|
42
|
+
version: '6.4'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: appraisal
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,9 +119,9 @@ executables: []
|
|
119
119
|
extensions: []
|
120
120
|
extra_rdoc_files: []
|
121
121
|
files:
|
122
|
+
- ".github/workflows/ruby.yml"
|
122
123
|
- ".gitignore"
|
123
124
|
- ".rspec"
|
124
|
-
- ".travis.yml"
|
125
125
|
- Appraisals
|
126
126
|
- CHANGELOG.md
|
127
127
|
- Gemfile
|
@@ -140,7 +140,7 @@ homepage: https://github.com/eddiezane/sendgrid-actionmailer
|
|
140
140
|
licenses:
|
141
141
|
- MIT
|
142
142
|
metadata: {}
|
143
|
-
post_install_message:
|
143
|
+
post_install_message:
|
144
144
|
rdoc_options: []
|
145
145
|
require_paths:
|
146
146
|
- lib
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
158
|
rubygems_version: 3.0.6
|
159
|
-
signing_key:
|
159
|
+
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: SendGrid support for ActionMailer.
|
162
162
|
test_files:
|