sendgrid-actionmailer 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/gemfiles/mail_2.5.gemfile.lock +1 -1
- data/gemfiles/mail_2.6.gemfile.lock +1 -1
- data/lib/sendgrid_actionmailer.rb +25 -16
- data/lib/sendgrid_actionmailer/version.rb +1 -1
- data/spec/lib/sendgrid_actionmailer_spec.rb +37 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 279c424c1fb91a3d43959b079eb62ff18cc49f4b
|
4
|
+
data.tar.gz: 612acbbe466f59ef1cfe8fb43d3e50b905b480c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efa913396a27fca27aaa83f3aa4ee00f9c59a8e5706d881d097e43e7a2d246fb06283f6c58a41ebe468fd997a6b2b7e56fe43b444597c31fe465bfaca2ff007e
|
7
|
+
data.tar.gz: 22c1f0dc2f693e4788cd508ccb2a4a7997e4437423ceea8c6eeaf5372dd2905c52447660dd0590f548f1f17dc2faa07410f3efebe1732af47a587502b88702fc
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'sendgrid_actionmailer/version'
|
2
2
|
require 'sendgrid_actionmailer/railtie' if defined? Rails
|
3
3
|
|
4
|
-
require '
|
4
|
+
require 'fileutils'
|
5
|
+
require 'tmpdir'
|
5
6
|
|
6
7
|
require 'sendgrid-ruby'
|
7
8
|
|
@@ -17,7 +18,7 @@ module SendGridActionMailer
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def deliver!(mail)
|
20
|
-
|
21
|
+
attachment_temp_dirs = []
|
21
22
|
from = mail[:from].addrs.first
|
22
23
|
|
23
24
|
email = SendGrid::Mail.new do |m|
|
@@ -96,21 +97,30 @@ module SendGridActionMailer
|
|
96
97
|
when 'text/html'
|
97
98
|
# HTML
|
98
99
|
email.html = mail.body.decoded
|
99
|
-
when 'multipart/alternative', 'multipart/mixed'
|
100
|
+
when 'multipart/alternative', 'multipart/mixed', 'multipart/related'
|
100
101
|
email.html = mail.html_part.decoded if mail.html_part
|
101
102
|
email.text = mail.text_part.decoded if mail.text_part
|
102
103
|
|
103
|
-
# This needs to be done better
|
104
104
|
mail.attachments.each do |a|
|
105
|
-
#
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
105
|
+
# Write the attachment into a temporary location, since sendgrid-ruby
|
106
|
+
# expects to deal with files.
|
107
|
+
#
|
108
|
+
# We write to a temporary directory (instead of a tempfile) and then
|
109
|
+
# use the original filename inside there, since sendgrid-ruby's
|
110
|
+
# add_content method pulls the filename from the path (so tempfiles
|
111
|
+
# would lead to random filenames).
|
112
|
+
temp_dir = Dir.mktmpdir('sendgrid-actionmailer')
|
113
|
+
attachment_temp_dirs << temp_dir
|
114
|
+
temp_path = File.join(temp_dir, a.filename)
|
115
|
+
File.open(temp_path, 'wb') do |file|
|
116
|
+
file.write(a.read)
|
117
|
+
end
|
118
|
+
|
119
|
+
if(mail.mime_type == 'multipart/related' && a.header[:content_id])
|
120
|
+
email.add_content(temp_path, a.header[:content_id].field.content_id)
|
121
|
+
else
|
122
|
+
email.add_attachment(temp_path, a.filename)
|
123
|
+
end
|
114
124
|
end
|
115
125
|
end
|
116
126
|
|
@@ -118,9 +128,8 @@ module SendGridActionMailer
|
|
118
128
|
ensure
|
119
129
|
# Close and delete the attachment tempfiles after the e-mail has been
|
120
130
|
# sent.
|
121
|
-
|
122
|
-
|
123
|
-
file.unlink
|
131
|
+
attachment_temp_dirs.each do |dir|
|
132
|
+
FileUtils.remove_entry_secure(dir)
|
124
133
|
end
|
125
134
|
end
|
126
135
|
end
|
@@ -193,6 +193,43 @@ module SendGridActionMailer
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
|
+
context 'multipart/related' do
|
197
|
+
before do
|
198
|
+
mail.content_type 'multipart/related'
|
199
|
+
mail.part do |part|
|
200
|
+
part.text_part = Mail::Part.new do
|
201
|
+
content_type 'text/plain'
|
202
|
+
body 'I heard you like pineapple.'
|
203
|
+
end
|
204
|
+
part.html_part = Mail::Part.new do
|
205
|
+
content_type 'text/html'
|
206
|
+
body 'I heard you like <b>pineapple</b>.'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
mail.attachments.inline['specs.rb'] = File.read(__FILE__)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'sets the text body' do
|
213
|
+
mailer.deliver!(mail)
|
214
|
+
expect(client.sent_mail.text).to eq('I heard you like pineapple.')
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'sets the html body' do
|
218
|
+
mailer.deliver!(mail)
|
219
|
+
expect(client.sent_mail.html)
|
220
|
+
.to eq('I heard you like <b>pineapple</b>.')
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'adds the inline attachment' do
|
224
|
+
expect(mail.attachments.first.read).to eq(File.read(__FILE__))
|
225
|
+
mailer.deliver!(mail)
|
226
|
+
content = client.sent_mail.contents.first
|
227
|
+
expect(content[:name]).to eq('specs.rb')
|
228
|
+
expect(content[:file].content_type.to_s).to eq('application/x-ruby')
|
229
|
+
expect(content[:cid].class).to eq(String)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
196
233
|
context 'SMTPAPI' do
|
197
234
|
context 'it is not JSON' do
|
198
235
|
before { mail['X-SMTPAPI'] = '<xml>JSON sucks!</xml>' }
|