sendcloud-mailer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +1 -1
- data/README.md +21 -14
- data/lib/sendcloud-mailer.rb +1 -0
- data/lib/sendcloud-mailer/base.rb +48 -6
- data/lib/sendcloud-mailer/interceptor.rb +12 -0
- data/lib/sendcloud-mailer/version.rb +1 -1
- data/sendcloud-mailer.gemspec +5 -5
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63d2c522c2d3c92ea6088c10e05900b256345434
|
4
|
+
data.tar.gz: 610da6bd64f69c570f2ba3c6438ef036eb21428f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f154355b8c697a7b0ed239e98ab952745677b6e2036354e5f5948a92c6330d98032208e2da2bf466c5ccd2894024dd9c204a141a95e2da4a363b8062f3f107bd
|
7
|
+
data.tar.gz: 3636ffc67cca86978bec151f73e601eed3eb3c121bf5672bdcc4dabde319c81d907e61b28cc4b917d8a62b64a2050387503179264ae3ec3e6ad01b6ca057f8fd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# sendcloud-mailer
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://api.travis-ci.org/emn178/sendcloud-mailer.png)](https://travis-ci.org/emn178/sendcloud-mailer)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/emn178/sendcloud-mailer/badge.svg?branch=master)](https://coveralls.io/r/emn178/sendcloud-mailer?branch=master)
|
4
5
|
|
5
|
-
|
6
|
+
An Action Mailer delivery method for SendCloud email service.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,20 +23,26 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
Set up delivery method and SendCloud settings in you rails config, eg. `config/environments/production.rb`
|
27
|
+
```Ruby
|
28
|
+
config.action_mailer.delivery_method = :sendcloud
|
29
|
+
config.action_mailer.sendcloud_settings = {
|
30
|
+
:api_user => 'USER',
|
31
|
+
:api_key => 'KEY'
|
32
|
+
}
|
33
|
+
```
|
34
|
+
If you use SMTP, you can add this interecptor to fix the problem that SendCloud does not accept <HTML> tag.
|
35
|
+
```Ruby
|
36
|
+
ActionMailer::Base.register_interceptor(SendcloudMailer::Interceptor)
|
37
|
+
```
|
36
38
|
|
39
|
+
## Notice
|
40
|
+
This gem is to send email by using SendCloud API, but the API can only support single attachment.
|
37
41
|
|
38
42
|
## License
|
39
43
|
|
40
44
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
45
|
|
46
|
+
## Contact
|
47
|
+
The project's website is located at https://github.com/emn178/sendcloud-mailer
|
48
|
+
Author: Chen, Yi-Cyuan (emn178@gmail.com)
|
data/lib/sendcloud-mailer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
1
3
|
module SendcloudMailer
|
2
4
|
class Base
|
3
5
|
attr_accessor :settings
|
@@ -14,14 +16,27 @@ module SendcloudMailer
|
|
14
16
|
:apiKey => settings[:api_key],
|
15
17
|
:from => from,
|
16
18
|
:to => to,
|
19
|
+
:cc => cc,
|
20
|
+
:bcc => bcc,
|
17
21
|
:subject => mail.subject,
|
18
22
|
:html => html,
|
19
|
-
:plain => plain
|
23
|
+
:plain => plain,
|
24
|
+
:attachments => attachments
|
20
25
|
}
|
26
|
+
params.delete_if { |k, v| v.nil? }
|
27
|
+
|
28
|
+
result = RestClient.post( 'http://api.sendcloud.net/apiv2/mail/send', params )
|
29
|
+
json = JSON.parse(result.force_encoding('UTF-8'))
|
30
|
+
error(json) unless json["result"]
|
31
|
+
unless @file.nil?
|
32
|
+
File.unlink(@file.path) rescue nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
21
37
|
|
22
|
-
|
23
|
-
|
24
|
-
ActionMailer::Base.logger.error(json) unless json["result"] && !ActionMailer::Base.logger.nil?
|
38
|
+
def error(message)
|
39
|
+
ActionMailer::Base.logger.error(message) unless ActionMailer::Base.logger.nil?
|
25
40
|
end
|
26
41
|
|
27
42
|
def from
|
@@ -29,8 +44,23 @@ module SendcloudMailer
|
|
29
44
|
end
|
30
45
|
|
31
46
|
def to
|
32
|
-
addresses
|
33
|
-
|
47
|
+
addresses 'To'
|
48
|
+
end
|
49
|
+
|
50
|
+
def cc
|
51
|
+
addresses 'Cc'
|
52
|
+
end
|
53
|
+
|
54
|
+
def bcc
|
55
|
+
addresses 'Bcc'
|
56
|
+
end
|
57
|
+
|
58
|
+
def addresses(name)
|
59
|
+
result = @mail.header.fields.find { |f| f.name == name }
|
60
|
+
unless result.nil?
|
61
|
+
addresses = result.address_list.addresses
|
62
|
+
addresses.join(';')
|
63
|
+
end
|
34
64
|
end
|
35
65
|
|
36
66
|
def html
|
@@ -40,5 +70,17 @@ module SendcloudMailer
|
|
40
70
|
def plain
|
41
71
|
@mail.multipart? ? (@mail.text_part ? @mail.text_part.body.decoded : nil) : @mail.body.decoded
|
42
72
|
end
|
73
|
+
|
74
|
+
def attachments
|
75
|
+
return nil if @mail.attachments.length == 0
|
76
|
+
|
77
|
+
@mail.attachments.each do | attachment |
|
78
|
+
filename = attachment.filename
|
79
|
+
# sendcloud api can only single file
|
80
|
+
@file = File.new(File.join(Dir.tmpdir, filename), 'w+b')
|
81
|
+
@file.write(attachment.body.decoded)
|
82
|
+
return @file
|
83
|
+
end
|
84
|
+
end
|
43
85
|
end
|
44
86
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SendcloudMailer
|
2
|
+
class Interceptor
|
3
|
+
def self.delivering_email(mail)
|
4
|
+
html = mail.html_part ? mail.html_part.body.decoded : nil
|
5
|
+
return if html.nil?
|
6
|
+
html = Nokogiri::HTML(html)
|
7
|
+
body = html.xpath('//body')[0]
|
8
|
+
body.name = 'div'
|
9
|
+
mail.html_part.body = body.to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/sendcloud-mailer.gemspec
CHANGED
@@ -6,11 +6,11 @@ require 'sendcloud-mailer/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "sendcloud-mailer"
|
8
8
|
spec.version = SendcloudMailer::VERSION
|
9
|
-
spec.authors = ["Chen Yi-Cyuan"]
|
9
|
+
spec.authors = ["Chen, Yi-Cyuan"]
|
10
10
|
spec.email = ["emn178@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{An Action Mailer delivery method for SendCloud email service.}
|
13
|
+
spec.description = %q{An Action Mailer delivery method for SendCloud email service.}
|
14
14
|
spec.homepage = "https://github.com/emn178/sendcloud-mailer"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency "actionmailer"
|
21
|
+
spec.add_dependency "rest-client"
|
21
22
|
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
# spec.add_development_dependency "rails"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "
|
26
|
+
spec.add_development_dependency "webmock"
|
27
27
|
spec.add_development_dependency "simplecov"
|
28
28
|
spec.add_development_dependency "coveralls"
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendcloud-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Chen Yi-Cyuan
|
7
|
+
- Chen, Yi-Cyuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: webmock
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -108,7 +122,7 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
|
-
description:
|
125
|
+
description: An Action Mailer delivery method for SendCloud email service.
|
112
126
|
email:
|
113
127
|
- emn178@gmail.com
|
114
128
|
executables: []
|
@@ -118,6 +132,7 @@ files:
|
|
118
132
|
- ".gitignore"
|
119
133
|
- ".rspec"
|
120
134
|
- ".travis.yml"
|
135
|
+
- CHANGELOG.md
|
121
136
|
- Gemfile
|
122
137
|
- LICENSE.txt
|
123
138
|
- README.md
|
@@ -126,6 +141,7 @@ files:
|
|
126
141
|
- bin/setup
|
127
142
|
- lib/sendcloud-mailer.rb
|
128
143
|
- lib/sendcloud-mailer/base.rb
|
144
|
+
- lib/sendcloud-mailer/interceptor.rb
|
129
145
|
- lib/sendcloud-mailer/version.rb
|
130
146
|
- sendcloud-mailer.gemspec
|
131
147
|
homepage: https://github.com/emn178/sendcloud-mailer
|
@@ -151,5 +167,5 @@ rubyforge_project:
|
|
151
167
|
rubygems_version: 2.4.8
|
152
168
|
signing_key:
|
153
169
|
specification_version: 4
|
154
|
-
summary:
|
170
|
+
summary: An Action Mailer delivery method for SendCloud email service.
|
155
171
|
test_files: []
|