resque-smtp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +9 -0
- data/lib/resque/smtp.rb +15 -0
- data/lib/resque/smtp/delivery_method.rb +30 -0
- data/lib/resque/smtp/email_job.rb +33 -0
- data/lib/resque/smtp/railtie.rb +19 -0
- data/lib/resque/smtp/version.rb +5 -0
- data/resque-smtp.gemspec +29 -0
- data/test/delivery_method_test.rb +27 -0
- data/test/email_job_test.rb +32 -0
- data/test/test_helper.rb +10 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cda4d7d88ad9db0fed99be98995835730f64bcb1
|
4
|
+
data.tar.gz: b009ba831cdcc2d84793475d1f8e650e9e39a9df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be8bcbbcb970df3961c4584982fc2209f5152c82ea3e841e24b495b1f638c6d351fb0408c4541b495f00b5fd7a67682f24db48fa8d6df3616c5ed9d4f79dee3a
|
7
|
+
data.tar.gz: 910bf8f344f5f42356d252587420e7596a0f969bb41cb2627ae3f539c9e8bcc1cfc97b1eeb57cbd20d3b487fd0f9498e7f2d577bd71d803c9e02c610e18d5bfd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Restorando
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Resque::SMTP
|
2
|
+
|
3
|
+
This gem allows you to do the mail delivery inside a Resque job.
|
4
|
+
|
5
|
+
What's the difference with other gems that send the email in Resque jobs?
|
6
|
+
|
7
|
+
The other gems aim to render and deliver the mail inside the job. Resque::SMTP only handles the deliver, this allows you to have workers that don't have all your dependencies (eg. Rails mailers), but can be retried if your mail provider fails.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'resque-smtp'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install resque-smtp
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Rails users
|
26
|
+
|
27
|
+
1. Configure wich mails you want to use resque-smtp.
|
28
|
+
This can be done to all your emails with in your `application.rb` (or in a per environment basis)
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
config.action_mailer.delivery_method = :resque_smtp
|
32
|
+
```
|
33
|
+
|
34
|
+
2. The default Resque queue name is: `mailing`, this can be changed with:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
config.action_mailer.resque_smtp_settings = { queue: "default" }
|
38
|
+
```
|
39
|
+
|
40
|
+
3. Done!
|
41
|
+
|
42
|
+
resque-smtp will use the `action_mailer.smtp_settings` to send the mails in the queue.
|
43
|
+
|
44
|
+
### Mail gem users
|
45
|
+
|
46
|
+
1. Configure your smtp settings in `Resque::SMTP.smtp_settings`
|
47
|
+
eg.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
Resque::SMTP.smtp_settings = { :address => "smtp.me.com",
|
51
|
+
:port => 587,
|
52
|
+
:domain => 'your.host.name',
|
53
|
+
:user_name => '<username>',
|
54
|
+
:password => '<password>',
|
55
|
+
:authentication => 'plain',
|
56
|
+
:enable_starttls_auto => true }
|
57
|
+
```
|
58
|
+
2. Configure Mail defaults to use Resque::SMTP (the queue parameter is optional, it defaults
|
59
|
+
to `"mailing"`)
|
60
|
+
eg.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
Mail.defaults do
|
64
|
+
delivery_method Resque::SMTP::DeliveryMethod, queue: "default"
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
3. Done!
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/resque/smtp.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'resque/smtp/version'
|
2
|
+
|
3
|
+
module Resque
|
4
|
+
module SMTP
|
5
|
+
autoload :EmailJob, 'resque/smtp/email_job'
|
6
|
+
autoload :DeliveryMethod, 'resque/smtp/delivery_method'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :smtp_settings
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'resque/smtp/railtie' if defined? Rails
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'resque/smtp'
|
2
|
+
require 'resque'
|
3
|
+
|
4
|
+
module Resque::SMTP
|
5
|
+
|
6
|
+
# Enqueues emails in Resque.
|
7
|
+
#
|
8
|
+
# Just set action_mailer delivery method to :resque_smtp and all
|
9
|
+
# emails will be enqueued.
|
10
|
+
#
|
11
|
+
# Delivery settings are not used as they are extracted from RCore.config
|
12
|
+
# at the moment emails are really delivered.
|
13
|
+
#
|
14
|
+
# If you want to have dedicated settings for this method you can set
|
15
|
+
# config.action_mailer.smtp_resque_settings in the application config.
|
16
|
+
#
|
17
|
+
class DeliveryMethod
|
18
|
+
|
19
|
+
def initialize(settings)
|
20
|
+
@settings = settings
|
21
|
+
EmailJob.queue = settings[:queue] if settings[:queue]
|
22
|
+
end
|
23
|
+
|
24
|
+
def deliver!(mail)
|
25
|
+
# Enqueue email dumped as string
|
26
|
+
Resque.enqueue(EmailJob, mail.encoded)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'resque/smtp'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module Resque::SMTP
|
5
|
+
# Class for sending emails enqueued in Resque.
|
6
|
+
#
|
7
|
+
# If you want to enqueue emails to be delivered later by this class
|
8
|
+
# you can do:
|
9
|
+
#
|
10
|
+
# mail = Mail.new(to: 'cosme@example.com')
|
11
|
+
# Resque.enqueue(Resque::SMTP::EmailJob, mail.encoded)
|
12
|
+
#
|
13
|
+
class EmailJob
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :queue
|
17
|
+
end
|
18
|
+
|
19
|
+
@queue = 'mailing'
|
20
|
+
|
21
|
+
def self.perform(encoded_mail)
|
22
|
+
|
23
|
+
mail = Mail.new(encoded_mail)
|
24
|
+
mail.delivery_method :smtp, Resque::SMTP.smtp_settings || {}
|
25
|
+
|
26
|
+
# Send without informing observers and interceptors and bypass
|
27
|
+
# checking perform_deliveries and raise_delivery_errors.
|
28
|
+
mail.delivery_method.deliver! mail
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'resque/smtp'
|
2
|
+
|
3
|
+
module Resque::SMTP
|
4
|
+
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "resque-smtp.action_mailer" do
|
7
|
+
|
8
|
+
ActiveSupport.on_load(:action_mailer) do
|
9
|
+
|
10
|
+
ActionMailer::Base.add_delivery_method :resque_smtp, Resque::SMTP::DeliveryMethod
|
11
|
+
|
12
|
+
Resque::SMTP.smtp_settings = ActionMailer::Base.smtp_settings
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/resque-smtp.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'resque/smtp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "resque-smtp"
|
8
|
+
spec.version = Resque::SMTP::VERSION
|
9
|
+
spec.authors = ["Restoradno"]
|
10
|
+
spec.email = ["dev@restorando.com"]
|
11
|
+
spec.description = %q{Deliver mail in a resque job}
|
12
|
+
spec.summary = %q{Adds a new delivery method to mail to allow delivering mails inside a job}
|
13
|
+
spec.homepage = "https://github.com/restorando/resque-smtp"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "resque", "~> 1.22"
|
22
|
+
spec.add_dependency "mail", "~> 2.5.4"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "actionmailer", ">= 3.2"
|
27
|
+
spec.add_development_dependency "minitest"
|
28
|
+
spec.add_development_dependency "resque_unit"
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module Resque::SMTP
|
5
|
+
|
6
|
+
describe DeliveryMethod do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@mail = Mail.new do
|
10
|
+
from "someone@somewhere.com"
|
11
|
+
to "someone_else@somewhere.com"
|
12
|
+
body "Some text"
|
13
|
+
delivery_method Resque::SMTP::DeliveryMethod
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#deliver' do
|
18
|
+
it 'enqueues a new email job with the encoded mail' do
|
19
|
+
@mail.deliver
|
20
|
+
|
21
|
+
assert_queued EmailJob, [@mail.encoded]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'minitest/mock'
|
3
|
+
|
4
|
+
module Resque::SMTP
|
5
|
+
|
6
|
+
describe EmailJob do
|
7
|
+
|
8
|
+
let(:encoded_mail) { "some encoded email" }
|
9
|
+
let(:mail) { MiniTest::Mock.new }
|
10
|
+
let(:smtp_delivery_method) { MiniTest::Mock.new }
|
11
|
+
|
12
|
+
describe 'running the job' do
|
13
|
+
|
14
|
+
it 'creates a new email with smtp as delivery method and delivers it' do
|
15
|
+
Mail.stub(:new, mail) do
|
16
|
+
mail.expect(:delivery_method, smtp_delivery_method, [:smtp, Hash])
|
17
|
+
mail.expect(:delivery_method, smtp_delivery_method)
|
18
|
+
smtp_delivery_method.expect(:deliver!, true, [mail])
|
19
|
+
|
20
|
+
EmailJob.perform("some encoded email")
|
21
|
+
|
22
|
+
smtp_delivery_method.verify
|
23
|
+
mail.verify
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-smtp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Restoradno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: resque
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.22'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.22'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.5.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.5.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionmailer
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
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'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: resque_unit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Deliver mail in a resque job
|
112
|
+
email:
|
113
|
+
- dev@restorando.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/resque/smtp.rb
|
125
|
+
- lib/resque/smtp/delivery_method.rb
|
126
|
+
- lib/resque/smtp/email_job.rb
|
127
|
+
- lib/resque/smtp/railtie.rb
|
128
|
+
- lib/resque/smtp/version.rb
|
129
|
+
- resque-smtp.gemspec
|
130
|
+
- test/delivery_method_test.rb
|
131
|
+
- test/email_job_test.rb
|
132
|
+
- test/test_helper.rb
|
133
|
+
homepage: https://github.com/restorando/resque-smtp
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Adds a new delivery method to mail to allow delivering mails inside a job
|
157
|
+
test_files:
|
158
|
+
- test/delivery_method_test.rb
|
159
|
+
- test/email_job_test.rb
|
160
|
+
- test/test_helper.rb
|