mail_engine 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ gem 'rack', :git => 'git://github.com/rack/rack.git'
10
10
  gem "liquid"
11
11
  gem 'kaminari', :git => 'https://github.com/amatsuda/kaminari.git'
12
12
  gem "carrierwave", :git => "git://github.com/jnicklas/carrierwave.git"
13
+ gem "mail_safe"
13
14
 
14
15
  group :development do
15
16
  gem "annotate"
data/README.mkd CHANGED
@@ -89,6 +89,22 @@ Add below line to the crontab list of your sever:
89
89
  ### check mail schedule for every 15 minutes ###
90
90
  */4 * * * * sh -c "cd /path/to/your/system && rake mail_engine:sendmail RAILS_ENV=production"
91
91
 
92
+ Configuration
93
+ =============
94
+
95
+ Below is the config for development env.
96
+
97
+ development:
98
+ log_mail: false # if you want to enable the mail log, set true.
99
+ user_class_name: "User" # Specify the User model in your system, which will used for mail schedule feature to find user groups and payloads.
100
+ mount_at: "/admin/mail_engine" # set the url path for mail engine.
101
+ access_check_method: "logged_in?" # set a method name which will execute before each page action in mail engine.
102
+ replacement_email: "dev@youdomain.com" # if you want to send all mail to one email, like on staging server or development environment, you can set this, or else don't set it.
103
+ sendgrid: # Below you need to set the sendgrid account info.
104
+ sendgrid_user: "you send grid username" #
105
+ sendgrid_key: "password" #
106
+ sendgrid_category: "my sendgrid category" #
107
+
92
108
 
93
109
  Usage
94
110
  =====
@@ -189,7 +205,7 @@ You can set a mail sending schedule, here are some useful setting items:
189
205
  5. Sending Period.
190
206
  6. Payloads which load from user model and send to template when sending.
191
207
  7. First send date time, this date will indicate when this mail will be send first time, and according to the seding period it will resend at the same time after one period.
192
- 8. You can set requirements, which been predefined in the system, let the mail not been sent if the requirements is unreached.
208
+ 8. You can control if run the schedule or not.
193
209
 
194
210
  ![Mail Schedule](https://github.com/hlxwell/mail-engine/raw/master/screenshots/schedule.png "Mail Schedule")
195
211
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -13,7 +13,7 @@
13
13
  # updated_at :datetime
14
14
  #
15
15
 
16
- class MailEngine::MailLog < ActiveRecord::Base
16
+ class MailEngine::MailLog < ActiveRecord::Base
17
17
  validates_presence_of :mail_template_path
18
18
 
19
19
  # # Callback of Mail gem when delivering mails
@@ -23,7 +23,7 @@ class MailEngine::MailLog < ActiveRecord::Base
23
23
  # # pp email.from
24
24
  # # pp email.subject
25
25
  # # pp email.mime_type
26
- #
26
+ #
27
27
  # ##################
28
28
  # # pp mail.mime_type
29
29
  # # pp mail.content_type
@@ -32,12 +32,12 @@ class MailEngine::MailLog < ActiveRecord::Base
32
32
  # # pp mail.subject #=> "This is the subject"
33
33
  # # pp mail.body.decoded #=> 'This is the body of the email...
34
34
  # ###################
35
- #
35
+ #
36
36
  # # pp mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
37
37
  # # pp mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
38
38
  # # pp mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
39
39
  # # pp mail.parts[1].content_type_parameters #=> {'name' => 'my.pdf'}
40
- #
40
+ #
41
41
  # # mail_type = email.header["X-mail-type"].value
42
42
  # # record = create! :recipient => email.to.join(","), :mail_type => mail_type
43
43
  # # email.encoded # kick email to set content_transfer_encoding
data/lib/mail_engine.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'active_support'
2
2
  require "action_view/template"
3
3
  require 'mail_engine/engine'
4
- require 'mail_engine/mail_log_subscriber'
5
- require 'mail_engine/zip_processor'
6
- require 'mail_engine/html_document_assets_replacer'
7
4
 
8
5
  module MailEngine
9
6
  extend ::ActiveSupport::Autoload
@@ -21,5 +18,4 @@ module MailEngine
21
18
  autoload :ActsAsMailReceiver
22
19
  autoload :Configuration
23
20
  autoload :MailTemplateResolver
24
- end
25
-
21
+ end
@@ -27,7 +27,13 @@ module ActionMailer
27
27
  # Add sendgrid header before sending mail.
28
28
  # Why here but not add to default_params of action_mailer? because the receiver email [:to] only can get here.
29
29
  if self.sendgrid_config
30
- self.sendgrid_config.set_send_to headers[:to]
30
+ # if add "replacement_email" option in config
31
+ receiver = if MailSafe::Config.replacement_address
32
+ MailSafe::Config.get_replacement_address(headers[:to])
33
+ else
34
+ headers[:to]
35
+ end
36
+ self.sendgrid_config.set_send_to receiver
31
37
  origin_mail(headers.merge(self.sendgrid_config.to_hash), &block)
32
38
  else
33
39
  origin_mail(headers, &block)
@@ -5,6 +5,9 @@ module MailEngine
5
5
  require 'kaminari'
6
6
  require 'deep_cloneable'
7
7
  require 'liquid'
8
+ require 'mail_engine/mail_log_subscriber'
9
+ require 'mail_engine/zip_processor'
10
+ require 'mail_engine/html_document_assets_replacer'
8
11
  require 'mail_engine/liquid_view_patch/liquid_view'
9
12
 
10
13
  initializer "mail_engine" do
@@ -45,6 +48,12 @@ module MailEngine
45
48
  if MailEngine::Base.current_config.present?
46
49
  raise "Please add :user_class_name config into mail_engine_config.yml." if MailEngine::Base.current_config["user_class_name"].blank?
47
50
  MailEngine::USER_MODEL = MailEngine::Base.current_config["user_class_name"].constantize unless defined?(MailEngine::USER_MODEL)
51
+
52
+ # in development mode all mails send to replacement_email_in_dev_mode
53
+ if defined?(MailSafe::Config) and replacement_email = MailEngine::Base.current_config["replacement_email"]
54
+ MailSafe::Config.internal_address_definition = /#{replacement_email}/
55
+ MailSafe::Config.replacement_address = replacement_email
56
+ end
48
57
  else
49
58
  puts "\e[1;31;40m[Mail Engine Warning]\e[0m Not found mail_engine_config.yml, so mail_engine won't be able to work."
50
59
  end
@@ -3,6 +3,7 @@ development:
3
3
  user_class_name: "User"
4
4
  mount_at: "/admin/mail_engine"
5
5
  access_check_method: "logged_in?"
6
+ replacement_email: "dev@youdomain.com"
6
7
  sendgrid:
7
8
  sendgrid_user: "you send grid username"
8
9
  sendgrid_key: "password"
@@ -13,6 +14,7 @@ test:
13
14
  user_class_name: "User"
14
15
  mount_at: "/admin/mail_engine"
15
16
  access_check_method: "logged_in?"
17
+ replacement_email: "dev@youdomain.com"
16
18
  sendgrid:
17
19
  sendgrid_user: "you send grid username"
18
20
  sendgrid_key: "password"
@@ -23,6 +25,7 @@ production:
23
25
  user_class_name: "User"
24
26
  mount_at: "/admin/mail_engine"
25
27
  access_check_method: "logged_in?"
28
+ replacement_email: "dev@youdomain.com"
26
29
  sendgrid:
27
30
  sendgrid_user: "you send grid username"
28
31
  sendgrid_key: "password"
data/mail_engine.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mail_engine}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["michael he"]
12
- s.date = %q{2011-03-09}
12
+ s.date = %q{2011-03-14}
13
13
  s.description = %q{Rails system mail management solution.}
14
14
  s.email = %q{hlxwell@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -618,6 +618,7 @@ Gem::Specification.new do |s|
618
618
  s.add_runtime_dependency(%q<liquid>, [">= 0"])
619
619
  s.add_runtime_dependency(%q<kaminari>, [">= 0"])
620
620
  s.add_runtime_dependency(%q<carrierwave>, [">= 0"])
621
+ s.add_runtime_dependency(%q<mail_safe>, [">= 0"])
621
622
  s.add_development_dependency(%q<annotate>, [">= 0"])
622
623
  s.add_development_dependency(%q<bluecloth>, [">= 0"])
623
624
  s.add_development_dependency(%q<yard>, [">= 0"])
@@ -635,6 +636,7 @@ Gem::Specification.new do |s|
635
636
  s.add_dependency(%q<liquid>, [">= 0"])
636
637
  s.add_dependency(%q<kaminari>, [">= 0"])
637
638
  s.add_dependency(%q<carrierwave>, [">= 0"])
639
+ s.add_dependency(%q<mail_safe>, [">= 0"])
638
640
  s.add_dependency(%q<annotate>, [">= 0"])
639
641
  s.add_dependency(%q<bluecloth>, [">= 0"])
640
642
  s.add_dependency(%q<yard>, [">= 0"])
@@ -653,6 +655,7 @@ Gem::Specification.new do |s|
653
655
  s.add_dependency(%q<liquid>, [">= 0"])
654
656
  s.add_dependency(%q<kaminari>, [">= 0"])
655
657
  s.add_dependency(%q<carrierwave>, [">= 0"])
658
+ s.add_dependency(%q<mail_safe>, [">= 0"])
656
659
  s.add_dependency(%q<annotate>, [">= 0"])
657
660
  s.add_dependency(%q<bluecloth>, [">= 0"])
658
661
  s.add_dependency(%q<yard>, [">= 0"])
@@ -17,9 +17,10 @@ class UserMailer < ActionMailer::Base
17
17
  @username = "Michael He"
18
18
 
19
19
  # html must below text
20
+ # should use subject in the db mail template.
20
21
  mail :to => to, :subject => "subject in mailer" do |f|
21
- f.html
22
22
  f.text
23
+ f.html
23
24
  end
24
25
  end
25
26
 
@@ -29,8 +30,8 @@ class UserMailer < ActionMailer::Base
29
30
 
30
31
  # html must below text
31
32
  mail :to => user.email do |f|
32
- f.html
33
33
  f.text
34
+ f.html
34
35
  end
35
36
  end
36
37
  end
@@ -17,23 +17,13 @@ Dummy::Application.configure do
17
17
  # Don't care if the mailer can't send
18
18
  config.action_mailer.perform_deliveries = true
19
19
  config.action_mailer.raise_delivery_errors = true
20
- config.action_mailer.delivery_method = :test
21
-
22
- # config.action_mailer.smtp_settings = {
23
- # :address => "smtp.gmail.com",
24
- # :port => 587,
25
- # :domain => 'itjob.fm',
26
- # :user_name => 'itjob.fm',
27
- # :password => 'whoafeedback',
28
- # :authentication => 'plain',
29
- # :enable_starttls_auto => true
30
- # }
20
+ config.action_mailer.delivery_method = :smtp
31
21
 
32
22
  config.action_mailer.smtp_settings = {
33
23
  :address => "smtp.sendgrid.net",
34
24
  :port => 25,
35
25
  :domain => 'smtp.sendgrid.met',
36
- :user_name => "a@theplant.jp",
26
+ :user_name => "",
37
27
  :password => "",
38
28
  :authentication => :plain
39
29
  }
@@ -48,7 +48,7 @@ Dummy::Application.routes.draw do
48
48
 
49
49
  # You can have the root of your site routed with "root"
50
50
  # just remember to delete public/index.html.
51
- root :to => redirect("/admin")
51
+ root :to => redirect("/admin/mail_engine")
52
52
 
53
53
  # See how all your routes lay out with "rake routes"
54
54
 
@@ -6,6 +6,15 @@ class UserMailerTest < ActionController::TestCase
6
6
  assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].present?
7
7
  end
8
8
 
9
+ should "send to safe mail address" do
10
+ replacement_email = "xxx@xxx.com"
11
+ MailSafe::Config.internal_address_definition = /#{replacement_email}/
12
+ MailSafe::Config.replacement_address = replacement_email
13
+
14
+ UserMailer.notify("x@x.com").deliver
15
+ assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].include?("[\"#{replacement_email}\"]")
16
+ end
17
+
9
18
  should "only send mail to the receiver" do
10
19
  UserMailer.notify("x@x.com").deliver
11
20
  assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].include?("[\"x@x.com\"]")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - michael he
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-09 00:00:00 +08:00
18
+ date: 2011-03-14 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -158,8 +158,8 @@ dependencies:
158
158
  version: "0"
159
159
  requirement: *id010
160
160
  prerelease: false
161
- name: annotate
162
- type: :development
161
+ name: mail_safe
162
+ type: :runtime
163
163
  - !ruby/object:Gem::Dependency
164
164
  version_requirements: &id011 !ruby/object:Gem::Requirement
165
165
  none: false
@@ -172,7 +172,7 @@ dependencies:
172
172
  version: "0"
173
173
  requirement: *id011
174
174
  prerelease: false
175
- name: bluecloth
175
+ name: annotate
176
176
  type: :development
177
177
  - !ruby/object:Gem::Dependency
178
178
  version_requirements: &id012 !ruby/object:Gem::Requirement
@@ -186,7 +186,7 @@ dependencies:
186
186
  version: "0"
187
187
  requirement: *id012
188
188
  prerelease: false
189
- name: yard
189
+ name: bluecloth
190
190
  type: :development
191
191
  - !ruby/object:Gem::Dependency
192
192
  version_requirements: &id013 !ruby/object:Gem::Requirement
@@ -200,7 +200,7 @@ dependencies:
200
200
  version: "0"
201
201
  requirement: *id013
202
202
  prerelease: false
203
- name: bundler
203
+ name: yard
204
204
  type: :development
205
205
  - !ruby/object:Gem::Dependency
206
206
  version_requirements: &id014 !ruby/object:Gem::Requirement
@@ -214,7 +214,7 @@ dependencies:
214
214
  version: "0"
215
215
  requirement: *id014
216
216
  prerelease: false
217
- name: jeweler
217
+ name: bundler
218
218
  type: :development
219
219
  - !ruby/object:Gem::Dependency
220
220
  version_requirements: &id015 !ruby/object:Gem::Requirement
@@ -228,7 +228,7 @@ dependencies:
228
228
  version: "0"
229
229
  requirement: *id015
230
230
  prerelease: false
231
- name: rcov
231
+ name: jeweler
232
232
  type: :development
233
233
  - !ruby/object:Gem::Dependency
234
234
  version_requirements: &id016 !ruby/object:Gem::Requirement
@@ -242,6 +242,20 @@ dependencies:
242
242
  version: "0"
243
243
  requirement: *id016
244
244
  prerelease: false
245
+ name: rcov
246
+ type: :development
247
+ - !ruby/object:Gem::Dependency
248
+ version_requirements: &id017 !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ hash: 3
254
+ segments:
255
+ - 0
256
+ version: "0"
257
+ requirement: *id017
258
+ prerelease: false
245
259
  name: reek
246
260
  type: :development
247
261
  description: Rails system mail management solution.