sendgrid-actionmailer 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Appraisals +7 -0
- data/README.md +69 -5
- data/Rakefile +7 -0
- data/gemfiles/mail_2.5.gemfile +7 -0
- data/gemfiles/mail_2.5.gemfile.lock +68 -0
- data/gemfiles/mail_2.6.gemfile +7 -0
- data/gemfiles/mail_2.6.gemfile.lock +63 -0
- data/lib/sendgrid-actionmailer.rb +1 -60
- data/lib/sendgrid_actionmailer.rb +106 -0
- data/lib/{sendgrid-actionmailer → sendgrid_actionmailer}/railtie.rb +0 -0
- data/lib/{sendgrid-actionmailer → sendgrid_actionmailer}/version.rb +1 -1
- data/sendgrid-actionmailer.gemspec +5 -2
- data/spec/lib/sendgrid_actionmailer_spec.rb +361 -0
- data/spec/spec_helper.rb +1 -0
- metadata +63 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74b9a08b495843840fdc6823142f28de25914d7b
|
4
|
+
data.tar.gz: 6e5fbd4cb655775fe3a67757479dafb41d32b55a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae8a64dc6b4f7e77eb5ab7226c2ba8b43e1ee5296f6b26817632b080efc238ba14ce41e9360768b54444cca4c41df047cf17d5823b5be9b1cbb474b9ab0afb9
|
7
|
+
data.tar.gz: d336ebf3f2d0659abfc158bdd585641db23c74271af318afc14f76b5c75009a11e8f358aa78d9a66b12c964e33d7d0d9578731cc10b7f57d624d94a7c707d892
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# SendGrid ActionMailer
|
2
2
|
|
3
|
-
SendGrid
|
3
|
+
An ActionMailer adapter to send email using SendGrid's HTTPS Web API (instead of SMTP).
|
4
|
+
|
5
|
+
[![BuildStatus](https://travis-ci.org/eddiezane/sendgrid-actionmailer.svg?branch=master)](https://travis-ci.org/eddiezane/sendgrid-actionmailer)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -19,12 +21,74 @@ Or install it yourself as:
|
|
19
21
|
|
20
22
|
## Usage
|
21
23
|
|
22
|
-
|
24
|
+
Create a [SendGrid API Key](https://app.sendgrid.com/settings/api_keys) for your application. Then edit `config/application.rb` or `config/environments/$ENVIRONMENT.rb` and add/change the following to the ActionMailer configuration:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
config.action_mailer.delivery_method = :sendgrid_actionmailer
|
28
|
+
config.action_mailer.sendgrid_actionmailer_settings = {
|
29
|
+
api_key: ENV['SENDGRID_API_KEY']
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
Normal ActionMailer usage will now transparently be sent using SendGrid's Web API.
|
34
|
+
|
35
|
+
### X-SMTPAPI
|
36
|
+
|
37
|
+
You may optionally set SendGrid's [X-SMTPAPI](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html) header on messages to control SendGrid specific functionality. This header must be set to a JSON string.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class UserMailer < ApplicationMailer
|
41
|
+
def welcome_email(user)
|
42
|
+
headers['X-SMTPAPI'] = {
|
43
|
+
category: ['newuser']
|
44
|
+
}.to_json
|
45
|
+
|
46
|
+
mail(to: user.email, subject: 'Welcome to My Awesome Site')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
The following `X-SMTPAPI` options are supported:
|
52
|
+
|
53
|
+
- `filters`
|
54
|
+
- `category`
|
55
|
+
- `send_at`
|
56
|
+
- `send_each_at`
|
57
|
+
- `section`
|
58
|
+
- `sub`
|
59
|
+
- `asm_group_id`
|
60
|
+
- `unique_args`
|
61
|
+
- `ip_pool`
|
62
|
+
|
63
|
+
#### X-SMTPAPI Defaults
|
64
|
+
|
65
|
+
Default values for the `X-SMTPAPI` header may be set at different levels using ActionMailer's normal options for setting default headers. However, since `X-SMTPAPI` is treated as a single string value, it's important to note that default values at different levels will not get merged together. So if you override the `X-SMTPAPI` header at any level, you may need to repeat any default values at more specific levels.
|
66
|
+
|
67
|
+
Global defaults can be set inside `config/application.rb`:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
config.action_mailer.default_options = {
|
71
|
+
'X-SMTPAPI' => {
|
72
|
+
ip_pool: 'marketing_ip_pool'
|
73
|
+
}.to_json
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
Per-mailer defaults can be set inside an ActionMailer class:
|
23
78
|
|
24
|
-
|
25
|
-
|
79
|
+
```ruby
|
80
|
+
class NewsletterMailer < ApplicationMailer
|
81
|
+
default('X-SMTPAPI' => {
|
82
|
+
category: ['newsletter'],
|
26
83
|
|
27
|
-
|
84
|
+
# Assuming the above "config.action_mailer.default_options" global default
|
85
|
+
# example, the default "ip_pool" value must be repeated here if you want
|
86
|
+
# that default value to also apply to this specific mailer that's
|
87
|
+
# specifying it's own default X-SMTPAPI value.
|
88
|
+
ip_pool: 'marketing_ip_pool'
|
89
|
+
}.to_json)
|
90
|
+
end
|
91
|
+
```
|
28
92
|
|
29
93
|
## Contributing
|
30
94
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
sendgrid-actionmailer (0.0.5)
|
5
|
+
mail (~> 2.5)
|
6
|
+
sendgrid-ruby (~> 0.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
appraisal (2.1.0)
|
12
|
+
bundler
|
13
|
+
rake
|
14
|
+
thor (>= 0.14.0)
|
15
|
+
diff-lcs (1.2.5)
|
16
|
+
domain_name (0.5.20160310)
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
18
|
+
http-cookie (1.0.2)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
mail (2.5.4)
|
21
|
+
mime-types (~> 1.16)
|
22
|
+
treetop (~> 1.4.8)
|
23
|
+
mime-types (1.25.1)
|
24
|
+
netrc (0.11.0)
|
25
|
+
polyglot (0.3.5)
|
26
|
+
rake (11.1.2)
|
27
|
+
rest-client (1.8.0)
|
28
|
+
http-cookie (>= 1.0.2, < 2.0)
|
29
|
+
mime-types (>= 1.16, < 3.0)
|
30
|
+
netrc (~> 0.7)
|
31
|
+
rspec (3.2.0)
|
32
|
+
rspec-core (~> 3.2.0)
|
33
|
+
rspec-expectations (~> 3.2.0)
|
34
|
+
rspec-mocks (~> 3.2.0)
|
35
|
+
rspec-core (3.2.3)
|
36
|
+
rspec-support (~> 3.2.0)
|
37
|
+
rspec-expectations (3.2.1)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.2.0)
|
40
|
+
rspec-mocks (3.2.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.2.0)
|
43
|
+
rspec-support (3.2.2)
|
44
|
+
sendgrid-ruby (0.0.3)
|
45
|
+
rest-client
|
46
|
+
smtpapi
|
47
|
+
smtpapi (0.1.0)
|
48
|
+
thor (0.19.1)
|
49
|
+
treetop (1.4.15)
|
50
|
+
polyglot
|
51
|
+
polyglot (>= 0.3.1)
|
52
|
+
unf (0.1.4)
|
53
|
+
unf_ext
|
54
|
+
unf_ext (0.0.7.2)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
appraisal (~> 2.1.0)
|
61
|
+
bundler (~> 1.6)
|
62
|
+
mail (= 2.5.4)
|
63
|
+
rake
|
64
|
+
rspec (~> 3.2.0)
|
65
|
+
sendgrid-actionmailer!
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.11.2
|
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
sendgrid-actionmailer (0.0.5)
|
5
|
+
mail (~> 2.5)
|
6
|
+
sendgrid-ruby (~> 0.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
appraisal (2.1.0)
|
12
|
+
bundler
|
13
|
+
rake
|
14
|
+
thor (>= 0.14.0)
|
15
|
+
diff-lcs (1.2.5)
|
16
|
+
domain_name (0.5.20160310)
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
18
|
+
http-cookie (1.0.2)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
mail (2.6.4)
|
21
|
+
mime-types (>= 1.16, < 4)
|
22
|
+
mime-types (2.99.1)
|
23
|
+
netrc (0.11.0)
|
24
|
+
rake (11.1.2)
|
25
|
+
rest-client (1.8.0)
|
26
|
+
http-cookie (>= 1.0.2, < 2.0)
|
27
|
+
mime-types (>= 1.16, < 3.0)
|
28
|
+
netrc (~> 0.7)
|
29
|
+
rspec (3.2.0)
|
30
|
+
rspec-core (~> 3.2.0)
|
31
|
+
rspec-expectations (~> 3.2.0)
|
32
|
+
rspec-mocks (~> 3.2.0)
|
33
|
+
rspec-core (3.2.3)
|
34
|
+
rspec-support (~> 3.2.0)
|
35
|
+
rspec-expectations (3.2.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.2.0)
|
38
|
+
rspec-mocks (3.2.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.2.0)
|
41
|
+
rspec-support (3.2.2)
|
42
|
+
sendgrid-ruby (0.0.3)
|
43
|
+
rest-client
|
44
|
+
smtpapi
|
45
|
+
smtpapi (0.1.0)
|
46
|
+
thor (0.19.1)
|
47
|
+
unf (0.1.4)
|
48
|
+
unf_ext
|
49
|
+
unf_ext (0.0.7.2)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
appraisal (~> 2.1.0)
|
56
|
+
bundler (~> 1.6)
|
57
|
+
mail (= 2.6.4)
|
58
|
+
rake
|
59
|
+
rspec (~> 3.2.0)
|
60
|
+
sendgrid-actionmailer!
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.11.2
|
@@ -1,60 +1 @@
|
|
1
|
-
require
|
2
|
-
require 'sendgrid-actionmailer/railtie' if defined? Rails
|
3
|
-
|
4
|
-
require 'tempfile'
|
5
|
-
|
6
|
-
require 'sendgrid-ruby'
|
7
|
-
|
8
|
-
module SendGridActionMailer
|
9
|
-
class DeliveryMethod
|
10
|
-
def initialize(params)
|
11
|
-
@client = SendGrid::Client.new do |c|
|
12
|
-
c.api_user = params[:api_user]
|
13
|
-
c.api_key = params[:api_key]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def deliver!(mail)
|
18
|
-
email = SendGrid::Mail.new do |m|
|
19
|
-
m.to = mail[:to].addresses
|
20
|
-
m.from = mail[:from]
|
21
|
-
m.subject = mail[:subject]
|
22
|
-
end
|
23
|
-
|
24
|
-
# TODO: This is pretty ugly
|
25
|
-
case mail.mime_type
|
26
|
-
when 'text/plain'
|
27
|
-
# Text
|
28
|
-
email.text = mail.body.decoded
|
29
|
-
when 'text/html'
|
30
|
-
# HTML
|
31
|
-
email.html = mail.body.decoded
|
32
|
-
when 'multipart/alternative'
|
33
|
-
# Text and HTML
|
34
|
-
email.text = mail.text_part.decoded
|
35
|
-
email.html = mail.html_part.decoded
|
36
|
-
when 'multipart/mixed'
|
37
|
-
# Text and/or HTML and Attachment
|
38
|
-
if mail.text_part.nil?
|
39
|
-
email.html = mail.html_part.decoded
|
40
|
-
elsif mail.html_part.nil?
|
41
|
-
email.text = mail.text_part.decoded
|
42
|
-
else
|
43
|
-
email.text = mail.text_part.decoded
|
44
|
-
email.html = mail.html_part.decoded
|
45
|
-
end
|
46
|
-
|
47
|
-
# This needs to be done better
|
48
|
-
mail.attachments.each do |a|
|
49
|
-
t = Tempfile.new("sendgrid-actionmailer#{rand(1000)}")
|
50
|
-
t.binmode
|
51
|
-
t.write(a.read)
|
52
|
-
email.add_attachment(t, a.filename)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
@client.send(email)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
1
|
+
require "sendgrid_actionmailer"
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'sendgrid_actionmailer/version'
|
2
|
+
require 'sendgrid_actionmailer/railtie' if defined? Rails
|
3
|
+
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
require 'sendgrid-ruby'
|
7
|
+
|
8
|
+
module SendGridActionMailer
|
9
|
+
class DeliveryMethod
|
10
|
+
attr_reader :client
|
11
|
+
|
12
|
+
def initialize(params)
|
13
|
+
@client = SendGrid::Client.new do |c|
|
14
|
+
c.api_user = params[:api_user]
|
15
|
+
c.api_key = params[:api_key]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def deliver!(mail)
|
20
|
+
from = mail[:from].addrs.first
|
21
|
+
|
22
|
+
email = SendGrid::Mail.new do |m|
|
23
|
+
m.to = mail[:to].addresses
|
24
|
+
m.cc = mail[:cc].addresses if mail[:cc]
|
25
|
+
m.bcc = mail[:bcc].addresses if mail[:bcc]
|
26
|
+
m.from = from.address
|
27
|
+
m.from_name = from.display_name
|
28
|
+
m.subject = mail.subject
|
29
|
+
end
|
30
|
+
|
31
|
+
smtpapi = mail['X-SMTPAPI']
|
32
|
+
if smtpapi && smtpapi.value
|
33
|
+
begin
|
34
|
+
data = JSON.parse(smtpapi.value)
|
35
|
+
|
36
|
+
if data['filters']
|
37
|
+
email.smtpapi.set_filters(data['filters'])
|
38
|
+
end
|
39
|
+
|
40
|
+
if data['category']
|
41
|
+
email.smtpapi.set_categories(data['category'])
|
42
|
+
end
|
43
|
+
|
44
|
+
if data['send_at']
|
45
|
+
email.smtpapi.set_send_at(data['send_at'])
|
46
|
+
end
|
47
|
+
|
48
|
+
if data['send_each_at']
|
49
|
+
email.smtpapi.set_send_each_at(data['send_each_at'])
|
50
|
+
end
|
51
|
+
|
52
|
+
if data['section']
|
53
|
+
email.smtpapi.set_sections(data['section'])
|
54
|
+
end
|
55
|
+
|
56
|
+
if data['sub']
|
57
|
+
email.smtpapi.set_substitutions(data['sub'])
|
58
|
+
end
|
59
|
+
|
60
|
+
if data['asm_group_id']
|
61
|
+
email.smtpapi.set_asm_group(data['asm_group_id'])
|
62
|
+
end
|
63
|
+
|
64
|
+
if data['unique_args']
|
65
|
+
email.smtpapi.set_unique_args(data['unique_args'])
|
66
|
+
end
|
67
|
+
|
68
|
+
if data['ip_pool']
|
69
|
+
email.smtpapi.set_ip_pool(data['ip_pool'])
|
70
|
+
end
|
71
|
+
rescue JSON::ParserError
|
72
|
+
raise ArgumentError, "X-SMTPAPI is not JSON: #{smtpapi.value}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# TODO: This is pretty ugly
|
77
|
+
case mail.mime_type
|
78
|
+
when 'text/plain'
|
79
|
+
# Text
|
80
|
+
email.text = mail.body.decoded
|
81
|
+
when 'text/html'
|
82
|
+
# HTML
|
83
|
+
email.html = mail.body.decoded
|
84
|
+
when 'multipart/alternative', 'multipart/mixed'
|
85
|
+
email.html = mail.html_part.decoded if mail.html_part
|
86
|
+
email.text = mail.text_part.decoded if mail.text_part
|
87
|
+
|
88
|
+
# This needs to be done better
|
89
|
+
mail.attachments.each do |a|
|
90
|
+
begin
|
91
|
+
t = Tempfile.new("sendgrid-actionmailer")
|
92
|
+
t.binmode
|
93
|
+
t.write(a.read)
|
94
|
+
t.flush
|
95
|
+
email.add_attachment(t, a.filename)
|
96
|
+
ensure
|
97
|
+
t.close
|
98
|
+
t.unlink
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
client.send(email)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'sendgrid_actionmailer/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'sendgrid-actionmailer'
|
@@ -18,8 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
21
|
+
spec.add_dependency 'mail', '~> 2.5'
|
22
|
+
spec.add_dependency 'sendgrid-ruby', '< 2.0'
|
22
23
|
|
23
24
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
25
|
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec', '~>3.2.0'
|
27
|
+
spec.add_development_dependency 'appraisal', '~> 2.1.0'
|
25
28
|
end
|
@@ -0,0 +1,361 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
module SendGridActionMailer
|
4
|
+
describe DeliveryMethod do
|
5
|
+
subject(:mailer) do
|
6
|
+
DeliveryMethod.new(api_user: 'user', api_key: 'key')
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestClient
|
10
|
+
attr_reader :sent_mail
|
11
|
+
|
12
|
+
def send(mail)
|
13
|
+
@sent_mail = mail
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#initialize' do
|
18
|
+
it 'configures the client API user' do
|
19
|
+
expect(mailer.client.api_user).to eq('user')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'configures the client API key' do
|
23
|
+
expect(mailer.client.api_key).to eq('key')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#deliver!' do
|
28
|
+
let(:client) { TestClient.new }
|
29
|
+
let(:mail) do
|
30
|
+
Mail.new(
|
31
|
+
to: 'test@sendgrid.com',
|
32
|
+
from: 'taco@cat.limo',
|
33
|
+
subject: 'Hello, world!'
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
before { allow(SendGrid::Client).to receive(:new).and_return(client) }
|
38
|
+
|
39
|
+
it 'sets to' do
|
40
|
+
mailer.deliver!(mail)
|
41
|
+
expect(client.sent_mail.to).to eq(%w[test@sendgrid.com])
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'there are ccs' do
|
45
|
+
before { mail.cc = 'burrito@cat.limo' }
|
46
|
+
|
47
|
+
it 'sets cc' do
|
48
|
+
mailer.deliver!(mail)
|
49
|
+
expect(client.sent_mail.cc).to eq(%w[burrito@cat.limo])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'there are bccs' do
|
54
|
+
before { mail.bcc = 'nachos@cat.limo' }
|
55
|
+
|
56
|
+
it 'sets bcc' do
|
57
|
+
mailer.deliver!(mail)
|
58
|
+
expect(client.sent_mail.bcc).to eq(%w[nachos@cat.limo])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'sets from' do
|
63
|
+
mailer.deliver!(mail)
|
64
|
+
expect(client.sent_mail.from).to eq('taco@cat.limo')
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'from contains a friendly name' do
|
68
|
+
before { mail.from = 'Taco Cat <taco@cat.limo>'}
|
69
|
+
|
70
|
+
it 'sets from' do
|
71
|
+
mailer.deliver!(mail)
|
72
|
+
expect(client.sent_mail.from).to eq('taco@cat.limo')
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'sets from_name' do
|
76
|
+
mailer.deliver!(mail)
|
77
|
+
expect(client.sent_mail.from_name).to eq('Taco Cat')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets subject' do
|
82
|
+
mailer.deliver!(mail)
|
83
|
+
expect(client.sent_mail.subject).to eq('Hello, world!')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'sets a text/plain body' do
|
87
|
+
mail.content_type = 'text/plain'
|
88
|
+
mail.body = 'I heard you like pineapple.'
|
89
|
+
mailer.deliver!(mail)
|
90
|
+
expect(client.sent_mail.text).to eq('I heard you like pineapple.')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'sets a text/html body' do
|
94
|
+
mail.content_type = 'text/html'
|
95
|
+
mail.body = 'I heard you like <b>pineapple</b>.'
|
96
|
+
mailer.deliver!(mail)
|
97
|
+
expect(client.sent_mail.html).to eq('I heard you like <b>pineapple</b>.')
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'multipart/alternative' do
|
101
|
+
before do
|
102
|
+
mail.content_type 'multipart/alternative'
|
103
|
+
mail.part do |part|
|
104
|
+
part.text_part = Mail::Part.new do
|
105
|
+
content_type 'text/plain'
|
106
|
+
body 'I heard you like pineapple.'
|
107
|
+
end
|
108
|
+
part.html_part = Mail::Part.new do
|
109
|
+
content_type 'text/html'
|
110
|
+
body 'I heard you like <b>pineapple</b>.'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sets the text body' do
|
116
|
+
mailer.deliver!(mail)
|
117
|
+
expect(client.sent_mail.text).to eq('I heard you like pineapple.')
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'sets the html body' do
|
121
|
+
mailer.deliver!(mail)
|
122
|
+
expect(client.sent_mail.html)
|
123
|
+
.to eq('I heard you like <b>pineapple</b>.')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'multipart/mixed' do
|
128
|
+
before do
|
129
|
+
mail.content_type 'multipart/mixed'
|
130
|
+
mail.part do |part|
|
131
|
+
part.text_part = Mail::Part.new do
|
132
|
+
content_type 'text/plain'
|
133
|
+
body 'I heard you like pineapple.'
|
134
|
+
end
|
135
|
+
part.html_part = Mail::Part.new do
|
136
|
+
content_type 'text/html'
|
137
|
+
body 'I heard you like <b>pineapple</b>.'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
mail.attachments['specs.rb'] = File.read(__FILE__)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'sets the text body' do
|
144
|
+
mailer.deliver!(mail)
|
145
|
+
expect(client.sent_mail.text).to eq('I heard you like pineapple.')
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'sets the html body' do
|
149
|
+
mailer.deliver!(mail)
|
150
|
+
expect(client.sent_mail.html)
|
151
|
+
.to eq('I heard you like <b>pineapple</b>.')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'adds the attachment' do
|
155
|
+
expect(mail.attachments.first.read).to eq(File.read(__FILE__))
|
156
|
+
mailer.deliver!(mail)
|
157
|
+
attachment = client.sent_mail.attachments.first
|
158
|
+
expect(attachment[:name]).to eq('specs.rb')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'SMTPAPI' do
|
163
|
+
context 'it is not JSON' do
|
164
|
+
before { mail['X-SMTPAPI'] = '<xml>JSON sucks!</xml>' }
|
165
|
+
|
166
|
+
it 'raises a useful error' do
|
167
|
+
expect { mailer.deliver!(mail) }.to raise_error(
|
168
|
+
ArgumentError,
|
169
|
+
"X-SMTPAPI is not JSON: <xml>JSON sucks!</xml>"
|
170
|
+
)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'filters are present' do
|
175
|
+
before do
|
176
|
+
mail['X-SMTPAPI'] = {
|
177
|
+
filters: {
|
178
|
+
clicktrack: {
|
179
|
+
settings: {
|
180
|
+
enable: 0
|
181
|
+
}
|
182
|
+
},
|
183
|
+
dkim: {
|
184
|
+
settings: {
|
185
|
+
domain: 'example.com',
|
186
|
+
use_from: false
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}.to_json
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'gets attached' do
|
194
|
+
mailer.deliver!(mail)
|
195
|
+
expect(client.sent_mail.smtpapi.filters).to eq({
|
196
|
+
'clicktrack' => {
|
197
|
+
'settings' => {
|
198
|
+
'enable' => 0
|
199
|
+
}
|
200
|
+
},
|
201
|
+
'dkim' => {
|
202
|
+
'settings' => {
|
203
|
+
'domain' => 'example.com',
|
204
|
+
'use_from' => false
|
205
|
+
}
|
206
|
+
}
|
207
|
+
})
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'a category is present' do
|
212
|
+
before do
|
213
|
+
mail['X-SMTPAPI'] = { category: 'food_feline' }.to_json
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'gets attached' do
|
217
|
+
mailer.deliver!(mail)
|
218
|
+
expect(client.sent_mail.smtpapi.category).to eq('food_feline')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'multiple categories are present' do
|
223
|
+
before do
|
224
|
+
mail['X-SMTPAPI'] = {
|
225
|
+
category: %w[food_feline cuisine_canine]
|
226
|
+
}.to_json
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'attaches them all' do
|
230
|
+
mailer.deliver!(mail)
|
231
|
+
expect(client.sent_mail.smtpapi.category).to eq([
|
232
|
+
'food_feline',
|
233
|
+
'cuisine_canine',
|
234
|
+
])
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'send_at is present' do
|
239
|
+
before do
|
240
|
+
mail['X-SMTPAPI'] = {
|
241
|
+
send_at: 1409348513
|
242
|
+
}.to_json
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'gets attached' do
|
246
|
+
mailer.deliver!(mail)
|
247
|
+
expect(client.sent_mail.smtpapi.send_at).to eq(1409348513)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'send_each_at is present' do
|
252
|
+
before do
|
253
|
+
mail['X-SMTPAPI'] = {
|
254
|
+
send_each_at: [1409348513, 1409348514]
|
255
|
+
}.to_json
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'gets attached' do
|
259
|
+
mailer.deliver!(mail)
|
260
|
+
expect(client.sent_mail.smtpapi.send_each_at).to eq([1409348513, 1409348514])
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context 'section is present' do
|
265
|
+
before do
|
266
|
+
mail['X-SMTPAPI'] = {
|
267
|
+
section: {
|
268
|
+
":sectionName1" => "section 1 text",
|
269
|
+
":sectionName2" => "section 2 text"
|
270
|
+
}
|
271
|
+
}.to_json
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'gets attached' do
|
275
|
+
mailer.deliver!(mail)
|
276
|
+
expect(client.sent_mail.smtpapi.section).to eq({
|
277
|
+
":sectionName1" => "section 1 text",
|
278
|
+
":sectionName2" => "section 2 text"
|
279
|
+
})
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'sub is present' do
|
284
|
+
before do
|
285
|
+
mail['X-SMTPAPI'] = {
|
286
|
+
sub: {
|
287
|
+
"-name-" => [
|
288
|
+
"John",
|
289
|
+
"Jane"
|
290
|
+
],
|
291
|
+
"-customerID-" => [
|
292
|
+
"1234",
|
293
|
+
"5678"
|
294
|
+
],
|
295
|
+
}
|
296
|
+
}.to_json
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'gets attached' do
|
300
|
+
mailer.deliver!(mail)
|
301
|
+
expect(client.sent_mail.smtpapi.sub).to eq({
|
302
|
+
"-name-" => [
|
303
|
+
"John",
|
304
|
+
"Jane"
|
305
|
+
],
|
306
|
+
"-customerID-" => [
|
307
|
+
"1234",
|
308
|
+
"5678"
|
309
|
+
],
|
310
|
+
})
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context 'asm_group_id is present' do
|
315
|
+
before do
|
316
|
+
mail['X-SMTPAPI'] = {
|
317
|
+
asm_group_id: 1
|
318
|
+
}.to_json
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'gets attached' do
|
322
|
+
mailer.deliver!(mail)
|
323
|
+
expect(client.sent_mail.smtpapi.asm_group_id).to eq(1)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'unique_args are present' do
|
328
|
+
before do
|
329
|
+
mail['X-SMTPAPI'] = {
|
330
|
+
unique_args: {
|
331
|
+
customerAccountNumber: "55555",
|
332
|
+
activationAttempt: "1",
|
333
|
+
}
|
334
|
+
}.to_json
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'gets attached' do
|
338
|
+
mailer.deliver!(mail)
|
339
|
+
expect(client.sent_mail.smtpapi.unique_args).to eq({
|
340
|
+
"customerAccountNumber" => "55555",
|
341
|
+
"activationAttempt" => "1",
|
342
|
+
})
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context 'ip_pool is present' do
|
347
|
+
before do
|
348
|
+
mail['X-SMTPAPI'] = {
|
349
|
+
ip_pool: "pool_name"
|
350
|
+
}.to_json
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'gets attached' do
|
354
|
+
mailer.deliver!(mail)
|
355
|
+
expect(client.sent_mail.smtpapi.ip_pool).to eq("pool_name")
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../lib/sendgrid_actionmailer'
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-actionmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eddie Zaneski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: mail
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sendgrid-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "<"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,34 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: appraisal
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.1.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.1.0
|
55
97
|
description: Use ActionMailer with SendGrid's Web API.
|
56
98
|
email:
|
57
99
|
- community@sendgrid.com
|
@@ -60,14 +102,24 @@ extensions: []
|
|
60
102
|
extra_rdoc_files: []
|
61
103
|
files:
|
62
104
|
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Appraisals
|
63
108
|
- Gemfile
|
64
109
|
- LICENSE.txt
|
65
110
|
- README.md
|
66
111
|
- Rakefile
|
112
|
+
- gemfiles/mail_2.5.gemfile
|
113
|
+
- gemfiles/mail_2.5.gemfile.lock
|
114
|
+
- gemfiles/mail_2.6.gemfile
|
115
|
+
- gemfiles/mail_2.6.gemfile.lock
|
67
116
|
- lib/sendgrid-actionmailer.rb
|
68
|
-
- lib/
|
69
|
-
- lib/
|
117
|
+
- lib/sendgrid_actionmailer.rb
|
118
|
+
- lib/sendgrid_actionmailer/railtie.rb
|
119
|
+
- lib/sendgrid_actionmailer/version.rb
|
70
120
|
- sendgrid-actionmailer.gemspec
|
121
|
+
- spec/lib/sendgrid_actionmailer_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
71
123
|
homepage: https://github.com/eddiezane/sendgrid-actionmailer
|
72
124
|
licenses:
|
73
125
|
- MIT
|
@@ -88,8 +140,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
140
|
version: '0'
|
89
141
|
requirements: []
|
90
142
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.6.2
|
92
144
|
signing_key:
|
93
145
|
specification_version: 4
|
94
146
|
summary: SendGrid support for ActionMailer.
|
95
|
-
test_files:
|
147
|
+
test_files:
|
148
|
+
- spec/lib/sendgrid_actionmailer_spec.rb
|
149
|
+
- spec/spec_helper.rb
|