mail_engine 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.mkd CHANGED
@@ -81,9 +81,9 @@ Add sendgrid smtp api configure:
81
81
  }
82
82
  end
83
83
  end
84
-
84
+
85
85
  For the detail information please check sendgrid.com.
86
-
86
+
87
87
  ** Step 6: **
88
88
 
89
89
  Add below line to production.rb or development.rb for specifing the host.
@@ -109,11 +109,11 @@ Below is the config for development env.
109
109
  user_locale_column: "locale" # Specify the locale column of user table, this will help sending correct language of mail to user.
110
110
  mount_at: "/admin/mail_engine" # set the url path for mail engine.
111
111
  access_check_method: "logged_in?" # set a method name which will execute before each page action in mail engine.
112
- 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.
112
+ intercept_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.
113
113
  sendgrid: # Below you need to set the sendgrid account info.
114
- sendgrid_user: "you send grid username" #
115
- sendgrid_key: "password" #
116
- sendgrid_category: "my sendgrid category" #
114
+ sendgrid_user: "you send grid username" #
115
+ sendgrid_key: "password" #
116
+ sendgrid_category: "my sendgrid category" #
117
117
 
118
118
 
119
119
  Usage
@@ -152,10 +152,19 @@ Currently only support above rails3.
152
152
 
153
153
  Tips
154
154
  ====
155
- Use below rake task, you can export local mail engine data, then import to production environment.
155
+ 1. Use below rake task, you can export local mail engine data, then import to production environment.
156
156
 
157
157
  rake mail_engine:export_mail_engine_database
158
158
 
159
+ 2. You can setup postfix or sendmail MTA on the server then use it to queue the mail locally.
160
+
161
+ http://support.sendgrid.com/entries/142079-getting-started-configuring-postfix
162
+
163
+ then you can set delivery_method as:
164
+
165
+ config.action_mailer.delivery_method = :sendmail
166
+
167
+
159
168
  Sendgrid Whitelabel Wizard
160
169
  ==========================
161
170
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -1,7 +1,7 @@
1
1
  class MailEngine::MailDispatcher < ActionMailer::Base
2
2
  default :from => MailEngine::Base.current_config["default_from"]
3
3
  sendgrid_header do
4
- category MailEngine::Base.current_config["sendgrid"]["category_name"]
4
+ category MailEngine::Base.current_config["sendgrid"]["sendgrid_category"]
5
5
  filters {
6
6
  opentrack "enable" => 1
7
7
  clicktrack "enable" => 1
@@ -146,7 +146,11 @@ class MailEngine::MailSchedule < ActiveRecord::Base
146
146
  MailEngine::USER_MODEL.send(self.user_group.to_sym).each do |user|
147
147
  puts "-> sending mail to #{user.email}" if Rails.env != 'test'
148
148
  ### FIXME user.email, what if user don't have email column.
149
- user_locale = user.send(MailEngine::Base.current_config["user_locale_column"])
149
+ user_locale = begin
150
+ user.send(MailEngine::Base.current_config["user_locale_column"])
151
+ rescue
152
+ I18n.default_locale
153
+ end
150
154
 
151
155
  begin
152
156
  # when there is default_locale been set, should fallback to default_locale template, when can't find the locale user in user settings.
@@ -205,7 +205,7 @@
205
205
  <span class='comment val'># Add sendgrid header before sending mail.</span>
206
206
  <span class='comment val'># Why here but not add to default_params of action_mailer? because the receiver email [:to] only can get here.</span>
207
207
  <span class='if if kw'>if</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='sendgrid_config identifier id'>sendgrid_config</span>
208
- <span class='comment val'># if add &quot;replacement_email&quot; option in config</span>
208
+ <span class='comment val'># if add &quot;intercept_email&quot; option in config</span>
209
209
  <span class='receiver identifier id'>receiver</span> <span class='assign token'>=</span> <span class='if if kw'>if</span> <span class='defined? defined kw'>defined?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='MailSafe constant id'>MailSafe</span><span class='colon2 op'>::</span><span class='Config constant id'>Config</span><span class='rparen token'>)</span> <span class='and and kw'>and</span> <span class='colon3 op'>::</span><span class='MailSafe constant id'>MailSafe</span><span class='colon2 op'>::</span><span class='Config constant id'>Config</span><span class='dot token'>.</span><span class='replacement_address identifier id'>replacement_address</span>
210
210
  <span class='colon3 op'>::</span><span class='MailSafe constant id'>MailSafe</span><span class='colon2 op'>::</span><span class='Config constant id'>Config</span><span class='dot token'>.</span><span class='get_replacement_address identifier id'>get_replacement_address</span><span class='lparen token'>(</span><span class='headers identifier id'>headers</span><span class='lbrack token'>[</span><span class='symbol val'>:to</span><span class='rbrack token'>]</span><span class='rparen token'>)</span>
211
211
  <span class='else else kw'>else</span>
data/doc/file.README.html CHANGED
@@ -157,7 +157,7 @@ it will used when generate resource url when upload zip file.</p>
157
157
  <span class='user_class_name identifier id'>user_class_name</span><span class='colon op'>:</span> <span class='string val'>&quot;User&quot;</span> <span class='comment val'># Specify the User model in your system, which will used for mail schedule feature to find user groups and payloads.</span>
158
158
  <span class='mount_at identifier id'>mount_at</span><span class='colon op'>:</span> <span class='string val'>&quot;/admin/mail_engine&quot;</span> <span class='comment val'># set the url path for mail engine.</span>
159
159
  <span class='access_check_method identifier id'>access_check_method</span><span class='colon op'>:</span> <span class='string val'>&quot;logged_in?&quot;</span> <span class='comment val'># set a method name which will execute before each page action in mail engine.</span>
160
- <span class='replacement_email identifier id'>replacement_email</span><span class='colon op'>:</span> <span class='string val'>&quot;dev@youdomain.com&quot;</span> <span class='comment val'># 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.</span>
160
+ <span class='intercept_email identifier id'>intercept_email</span><span class='colon op'>:</span> <span class='string val'>&quot;dev@youdomain.com&quot;</span> <span class='comment val'># 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.</span>
161
161
  <span class='sendgrid identifier id'>sendgrid</span><span class='colon op'>:</span> <span class='comment val'># Below you need to set the sendgrid account info.</span>
162
162
  <span class='sendgrid_user identifier id'>sendgrid_user</span><span class='colon op'>:</span> <span class='string val'>&quot;you send grid username&quot;</span> <span class='comment val'># </span>
163
163
  <span class='sendgrid_key identifier id'>sendgrid_key</span><span class='colon op'>:</span> <span class='string val'>&quot;password&quot;</span> <span class='comment val'># </span>
data/doc/index.html CHANGED
@@ -157,7 +157,7 @@ it will used when generate resource url when upload zip file.</p>
157
157
  <span class='user_class_name identifier id'>user_class_name</span><span class='colon op'>:</span> <span class='string val'>&quot;User&quot;</span> <span class='comment val'># Specify the User model in your system, which will used for mail schedule feature to find user groups and payloads.</span>
158
158
  <span class='mount_at identifier id'>mount_at</span><span class='colon op'>:</span> <span class='string val'>&quot;/admin/mail_engine&quot;</span> <span class='comment val'># set the url path for mail engine.</span>
159
159
  <span class='access_check_method identifier id'>access_check_method</span><span class='colon op'>:</span> <span class='string val'>&quot;logged_in?&quot;</span> <span class='comment val'># set a method name which will execute before each page action in mail engine.</span>
160
- <span class='replacement_email identifier id'>replacement_email</span><span class='colon op'>:</span> <span class='string val'>&quot;dev@youdomain.com&quot;</span> <span class='comment val'># 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.</span>
160
+ <span class='intercept_email identifier id'>intercept_email</span><span class='colon op'>:</span> <span class='string val'>&quot;dev@youdomain.com&quot;</span> <span class='comment val'># 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.</span>
161
161
  <span class='sendgrid identifier id'>sendgrid</span><span class='colon op'>:</span> <span class='comment val'># Below you need to set the sendgrid account info.</span>
162
162
  <span class='sendgrid_user identifier id'>sendgrid_user</span><span class='colon op'>:</span> <span class='string val'>&quot;you send grid username&quot;</span> <span class='comment val'># </span>
163
163
  <span class='sendgrid_key identifier id'>sendgrid_key</span><span class='colon op'>:</span> <span class='string val'>&quot;password&quot;</span> <span class='comment val'># </span>
@@ -16,9 +16,9 @@ module ActionMailer
16
16
  # Add sendgrid header before sending mail.
17
17
  # Why here but not add to default_params of action_mailer? because the receiver email [:to] only can get here.
18
18
  if self.sendgrid_config
19
- # if add "replacement_email" option in config
20
- receiver = if (replacement_email = MailEngine::Base.current_config["replacement_email"]).present?
21
- headers[:to] = replacement_email
19
+ # if add "intercept_email" option in config
20
+ receiver = if (intercept_email = MailEngine::Base.current_config["intercept_email"]).present?
21
+ headers[:to] = intercept_email
22
22
  else
23
23
  headers[:to]
24
24
  end
@@ -1,14 +1,65 @@
1
1
  module MailEngine
2
+ class ConfigurationError < StandardError; end
2
3
  # Load configure file from config/mail_engine_config.yml
3
4
  # you can access the config by MailEngine::Base.current_config[]
4
5
  class Configuration
5
6
  class << self
6
- def load
7
+ def load_and_check
7
8
  require 'erb' # make config file support erb tags. like <% %>
8
9
  config_path = File.join(Rails.root, "config", "mail_engine_config.yml")
9
10
  MailEngine::Base.configurations = {}
10
11
  MailEngine::Base.configurations = YAML::load(ERB.new(IO.read(config_path)).result) if File.exist?(config_path)
12
+ config_check
11
13
  end
14
+
15
+ ### Need check below config options
16
+ #
17
+ # log_mail: true
18
+ # user_class_name: "User"
19
+ # user_locale_column: "locale"
20
+ # mount_at: "/admin/mail_engine"
21
+ # intercept_email: "hlxwell@gmail.com"
22
+ # default_from: "hlxwell@gmail.com"
23
+ # access_check_method: "logged_in?"
24
+ # sendgrid:
25
+ # sendgrid_user: "a@theplant.jp"
26
+ # sendgrid_key: "plant^o^"
27
+ # sendgrid_category: "development"
28
+ #
29
+ def config_check
30
+ if MailEngine::Base.current_config.blank?
31
+ 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."
32
+ raise ConfigurationError.new("did't find config file at config/mail_engine_config.yml")
33
+ end
34
+
35
+ %w{log_mail user_class_name user_locale_column mount_at default_from access_check_method}.each do |option|
36
+ raise ConfigurationError.new("Please add :#{option} config into mail_engine_config.yml.") if MailEngine::Base.current_config[option].blank?
37
+ end
38
+
39
+ %w{sendgrid_category sendgrid_user sendgrid_key}.each do |option|
40
+ raise ConfigurationError.new("Please add :#{option} config under not :sendgrid into mail_engine_config.yml.") if MailEngine::Base.current_config["sendgrid"][option].blank?
41
+ end
42
+ rescue ConfigurationError => e
43
+ puts <<-NOTE
44
+ \e[1;31;40m[Mail Engine Warning - Below is a sample config]\e[0m
45
+ ===============================================
46
+ log_mail: true
47
+ user_class_name: 'User'
48
+ user_locale_column: 'locale'
49
+ mount_at: '/admin/mail_engine'
50
+ intercept_email: 'hlxwell@gmail.com'
51
+ default_from: 'hlxwell@gmail.com'
52
+ access_check_method: 'logged_in?'
53
+ sendgrid:
54
+ sendgrid_user: 'a@theplant.jp'
55
+ sendgrid_key: 'plant^o^'
56
+ sendgrid_category: 'development'
57
+ ===============================================
58
+ NOTE
59
+
60
+ raise e
61
+ end
62
+
12
63
  end
13
64
  end
14
65
  end
@@ -42,15 +42,9 @@ module MailEngine
42
42
 
43
43
  config.to_prepare do
44
44
  # load config
45
- MailEngine::Configuration.load
46
-
47
- # don't process config file if not fine it.
48
- if MailEngine::Base.current_config.present?
49
- raise "Please add :user_class_name config into mail_engine_config.yml." if MailEngine::Base.current_config["user_class_name"].blank?
50
- MailEngine::USER_MODEL = MailEngine::Base.current_config["user_class_name"].constantize unless defined?(MailEngine::USER_MODEL)
51
- else
52
- 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."
53
- end
45
+ MailEngine::Configuration.load_and_check
46
+
47
+ MailEngine::USER_MODEL = MailEngine::Base.current_config["user_class_name"].constantize unless defined?(MailEngine::USER_MODEL)
54
48
  end
55
49
  end
56
50
  end
@@ -5,9 +5,8 @@ development:
5
5
  mount_at: "/admin/mail_engine"
6
6
  access_check_method: "logged_in?"
7
7
  default_from: "your@email.address"
8
- replacement_email: "dev@youdomain.com"
8
+ intercept_email: "dev@youdomain.com"
9
9
  sendgrid:
10
- category_name: "you category name"
11
10
  sendgrid_user: "you send grid username"
12
11
  sendgrid_key: "password"
13
12
  sendgrid_category: "my sendgrid category"
@@ -18,10 +17,9 @@ test:
18
17
  user_locale_column: "locale"
19
18
  mount_at: "/admin/mail_engine"
20
19
  access_check_method: "logged_in?"
21
- replacement_email: "dev@youdomain.com"
20
+ intercept_email: "dev@youdomain.com"
22
21
  default_from: "your@email.address"
23
22
  sendgrid:
24
- category_name: "you category name"
25
23
  sendgrid_user: "you send grid username"
26
24
  sendgrid_key: "password"
27
25
  sendgrid_category: "my sendgrid category"
@@ -34,7 +32,6 @@ production:
34
32
  access_check_method: "logged_in?"
35
33
  default_from: "your@email.address"
36
34
  sendgrid:
37
- category_name: "you category name"
38
35
  sendgrid_user: "you send grid username"
39
36
  sendgrid_key: "password"
40
37
  sendgrid_category: "my sendgrid category"
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.12"
8
+ s.version = "0.1.13"
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-17}
12
+ s.date = %q{2011-03-18}
13
13
  s.description = %q{Rails system mail management solution.}
14
14
  s.email = %q{hlxwell@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,7 +1,7 @@
1
1
  class UserMailer < ActionMailer::Base
2
2
  default :from => MailEngine::Base.current_config["default_from"]
3
3
  sendgrid_header do
4
- category MailEngine::Base.current_config["sendgrid"]["category_name"]
4
+ category MailEngine::Base.current_config["sendgrid"]["sendgrid_category"]
5
5
 
6
6
  filters {
7
7
  opentrack "enable" => 1
@@ -10,7 +10,7 @@ class CreateMailSchedules < ActiveRecord::Migration
10
10
  t.string :payload
11
11
  t.datetime :first_send_at
12
12
  t.datetime :last_sent_at
13
- t.boolean :available
13
+ t.boolean :available, :default => false
14
14
  t.string :default_locale
15
15
 
16
16
  t.timestamps
@@ -7,7 +7,7 @@ class UserMailerTest < ActionController::TestCase
7
7
  end
8
8
 
9
9
  should "send to safe mail address" do
10
- MailEngine::Base.current_config["replacement_email"] = "xxx@xxx.com"
10
+ MailEngine::Base.current_config["intercept_email"] = "xxx@xxx.com"
11
11
  mail = UserMailer.notify("x@x.com").deliver
12
12
  assert_equal mail.to, ["xxx@xxx.com"]
13
13
  assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].include?("[\"xxx@xxx.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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 12
10
- version: 0.1.12
9
+ - 13
10
+ version: 0.1.13
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-17 00:00:00 +08:00
18
+ date: 2011-03-18 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency