idlemailer 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -47
- data/lib/idlemailer/config.rb +3 -2
- data/lib/idlemailer/defaults.rb +2 -1
- data/lib/idlemailer/message.rb +10 -6
- data/lib/idlemailer/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 347bc7e19b8427031ed9246730a710ca7ad8893f
|
4
|
+
data.tar.gz: 4e44c6a7525787ab0576655f863fa31b5d1359ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 707144b2594688f8b838dc2eb3aa35f553c2f9bc188a0be8f6f812ccc7e801005a1068691ca8cf54d699564037e4a5fe0bb0f8e4c491425915dedc3e2ae8ef28
|
7
|
+
data.tar.gz: a349486802b1245cf60dd885b85dfbbb74ea266ee077a0ff0f1b366d864fb2004fd7718ecac63d674ce2bf667d8c2f64dced20935c78aae4f9371fd8a1f931e2
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IdleMailer
|
2
2
|
|
3
|
-
A lightweight alternative to ActionMailer for hipsters who use Ruby but not Rails. Powered by [mail](http://www.rubydoc.info/gems/mail). Great for API-only backends that need to send email.
|
3
|
+
A lightweight (~100 line) alternative to ActionMailer for hipsters who use Ruby but not Rails. Powered by [mail](http://www.rubydoc.info/gems/mail). Great for API-only backends that need to send email.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -11,68 +11,81 @@ A lightweight alternative to ActionMailer for hipsters who use Ruby but not Rail
|
|
11
11
|
|
12
12
|
IdleMailer is all about providing mailer classes and templates. But [the mail gem](http://www.rubydoc.info/gems/mail) has a great API, so you have unfettered access to it in your mailers through the "mail" object.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
```ruby
|
15
|
+
# Define your mailer class
|
16
|
+
class WidgetMailer
|
17
|
+
include IdleMailer::Mailer
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def initialize(user, widget)
|
20
|
+
mail.to = user.email
|
21
|
+
mail.subject = "Widget #{widget.sku}"
|
22
|
+
@widget = widget
|
23
|
+
end
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
# Create widget.html.erb and/or widget.text.erb templates.
|
27
|
+
# They'll have access to instance variables like @widget above.
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# Send your mail
|
30
|
+
mailer = WidgetMailer.new(current_user, widget)
|
31
|
+
mailer.deliver
|
32
|
+
```
|
31
33
|
|
32
34
|
## Configure
|
33
35
|
|
34
36
|
These are the default options. Salt to taste.
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
38
|
+
```ruby
|
39
|
+
IdleMailer.config do |config|
|
40
|
+
# Directory containing the mailer templates
|
41
|
+
config.templates = Pathname.new(Dir.getwd).join('templates')
|
42
|
+
|
43
|
+
# Name of the layout template. Here, the file(s) would be named
|
44
|
+
# mailer_layout.html.erb and/or mailer_layout.text.erb.
|
45
|
+
config.layout = 'mailer_layout'
|
46
|
+
|
47
|
+
# Email delivery method (mail gem). Set to :test when testing or when developing locally
|
48
|
+
config.delivery_method = :smtp
|
49
|
+
|
50
|
+
# Delivery options (mail gem)
|
51
|
+
config.delivery_options = {
|
52
|
+
user_name: ENV['MAIL_USER'],
|
53
|
+
password: ENV['MAIL_PASSWORD'],
|
54
|
+
domain: ENV['MAIL_DOMAIN'],
|
55
|
+
address: ENV['MAIL_ADDRESS'],
|
56
|
+
port: ENV['MAIL_PORT'] || 587,
|
57
|
+
authentication: ENV['MAIL_AUTHENTICATION'] || 'plain',
|
58
|
+
enable_starttls_auto: (ENV['MAIL_TLS'] ? true : false)
|
59
|
+
}
|
60
|
+
|
61
|
+
# Default "from" address for all mailers
|
62
|
+
config.default_from = nil
|
63
|
+
|
64
|
+
# Log sent emails (require 'logger')
|
65
|
+
# config.logger = Logger.new($stdout)
|
66
|
+
# config.logger = Logger.new('log/mailers.log')
|
67
|
+
config.logger = nil
|
68
|
+
|
69
|
+
# Write full message body to log (if enabled). Otherwise, only message headers are logged.
|
70
|
+
config.log_body = false
|
71
|
+
end
|
72
|
+
```
|
64
73
|
|
65
74
|
## Testing
|
66
75
|
|
67
76
|
Put the mailer in testing mode:
|
68
77
|
|
69
|
-
|
70
|
-
|
71
|
-
|
78
|
+
```ruby
|
79
|
+
IdleMailer.config do |config|
|
80
|
+
config.delivery_method = :test
|
81
|
+
end
|
82
|
+
```
|
72
83
|
|
73
84
|
Then use mail gem's built in testing helpers in your specs:
|
74
85
|
|
75
|
-
|
86
|
+
```ruby
|
87
|
+
sent = Mail::TestMailer.deliveries.any? { |mail| mail.to.include? @user.email }
|
88
|
+
```
|
76
89
|
|
77
90
|
## License
|
78
91
|
|
data/lib/idlemailer/config.rb
CHANGED
@@ -5,8 +5,9 @@ module IdleMailer
|
|
5
5
|
# delivery_method Symbol like :smtp or :test (see the mail gem for all options)
|
6
6
|
# delivery_options Hash of delivery options (see the mail gem for all options)
|
7
7
|
# default_from Default "from" address if it's left blank
|
8
|
-
#
|
9
|
-
|
8
|
+
# logger a Logger object for logging email
|
9
|
+
# log_body if true, the entire message body will be logged (instead of just the headers) (default false)
|
10
|
+
Config = Struct.new(:templates, :layout, :delivery_method, :delivery_options, :default_from, :logger, :log_body)
|
10
11
|
@config = Config.new
|
11
12
|
|
12
13
|
# Takes a block and hands it an IdleMailer::Config object
|
data/lib/idlemailer/defaults.rb
CHANGED
data/lib/idlemailer/message.rb
CHANGED
@@ -8,13 +8,11 @@ module IdleMailer
|
|
8
8
|
|
9
9
|
# Initialize a new message
|
10
10
|
def initialize(mail, mailer)
|
11
|
-
@mail = mail
|
12
|
-
@mailer = mailer
|
11
|
+
@mail, @mailer = mail, mailer
|
13
12
|
end
|
14
13
|
|
15
14
|
# Deliver mail
|
16
15
|
def deliver!
|
17
|
-
mail.from IdleMailer.config.default_from if mail.from.nil?
|
18
16
|
if has_template? 'html'
|
19
17
|
html_body = layout('html') { body('html') }
|
20
18
|
mail.html_part do
|
@@ -26,9 +24,11 @@ module IdleMailer
|
|
26
24
|
text_body = layout('text') { body('text') }
|
27
25
|
mail.text_part { body text_body }
|
28
26
|
end
|
29
|
-
|
27
|
+
config = IdleMailer.config
|
28
|
+
mail.from config.default_from if mail.from.nil?
|
29
|
+
mail.delivery_method config.delivery_method, config.delivery_options
|
30
30
|
message = mail.deliver
|
31
|
-
|
31
|
+
config.logger.info(config.log_body ? message.to_s : message) if config.logger
|
32
32
|
message
|
33
33
|
end
|
34
34
|
|
@@ -55,7 +55,11 @@ module IdleMailer
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def template_name
|
58
|
-
@name ||= mailer.class.name.
|
58
|
+
@name ||= mailer.class.name.
|
59
|
+
gsub(/::/, File::SEPARATOR).
|
60
|
+
sub(/Mailer$/, '').
|
61
|
+
gsub(/([a-z])([A-Z])/, "\\1_\\2").
|
62
|
+
downcase
|
59
63
|
end
|
60
64
|
|
61
65
|
def template_path(name, type)
|
data/lib/idlemailer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idlemailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -58,8 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.4.5
|
61
|
+
rubygems_version: 2.4.5.1
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: A lightweight alternative to ActionMailer
|
65
65
|
test_files: []
|
66
|
+
has_rdoc:
|