action_mailer_provider 0.1.1
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/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/action_mailer_provider.gemspec +26 -0
- data/lib/action_mailer_provider.rb +5 -0
- data/lib/action_mailer_provider/configuration.rb +30 -0
- data/lib/action_mailer_provider/strategies.rb +19 -0
- data/lib/action_mailer_provider/strategies/abstract_smtp_strategy.rb +31 -0
- data/lib/action_mailer_provider/strategies/gmail.rb +14 -0
- data/lib/action_mailer_provider/strategies/zoho.rb +16 -0
- data/lib/action_mailer_provider/version.rb +3 -0
- data/lib/generators/action_mailer_provider/install_generator.rb +42 -0
- data/lib/generators/action_mailer_provider/templates/initializer.rb.erb +18 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2b866699a8b9bf2a5cbe6f0d224a592abf75ee8
|
4
|
+
data.tar.gz: 7ecda3edba46ca85f2539f52fc3efa519562a7cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae1ba135359ad8b5233b856671f1a3632257e260be15fef7c504d9ebf982c49aa18f2fb032ee28fff7347d689388197099a7120e9a3c9a764d6ed7069667ce3e
|
7
|
+
data.tar.gz: d0e949408c1ff4a3f8853b0b4d92d526c5d93097debcd9888b8bf4fbc5234344c8534f9b0523b74620ca74a5f9572adeb13e43dbadf74ed8411a16c45c2d6635
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Miguel Palhas
|
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,51 @@
|
|
1
|
+
# ActionMailerProvider
|
2
|
+
|
3
|
+
Never again shall you have production errors due to wrong mail configuration
|
4
|
+
|
5
|
+
This is a simple helper gem that configures your rails SMTP settings according
|
6
|
+
to your provider.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'action_mailer_provider'
|
13
|
+
|
14
|
+
And bundle:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Finally, use the generator to create the initializer file with your desired
|
19
|
+
settings. By default, all data will be fetched from environment variables,
|
20
|
+
although you can override that in the generator prompt.
|
21
|
+
I do recommend using the environment variables through [dotenv](https://github.com/bkeepers/dotenv)) or another similar tool, as they are easier to update later, and more secure (your email password in kept in an untracked file)
|
22
|
+
|
23
|
+
```
|
24
|
+
$ rails generate action_mailer_provider:install
|
25
|
+
By default, values will be fetched through env variables. Would you like to customize them instead? [yN] y
|
26
|
+
What provider would you like to use? [ENV['EMAIL_PROVIDER']] zoho
|
27
|
+
What's your email domain? [ENV['EMAIL_DOMAIN']] my.domain.com
|
28
|
+
What's the email address to use? [ENV['EMAIL_USERNAME']] my-account@my.domain.com
|
29
|
+
Email password [ENV['EMAIL_PASSWORD']] my-password
|
30
|
+
create config/initializers/action_mailer_provider.rb
|
31
|
+
```
|
32
|
+
|
33
|
+
## Providers
|
34
|
+
|
35
|
+
Currently the only supported providers are [ZohoMail](https://www.zoho.com/mail/) (`zoho`) and [Gmail](mail.google.com) (`gmail`)
|
36
|
+
Each of them requires only that you speficy your custom domain, and default
|
37
|
+
email account and password to use. The rest (smtp address, port, ssl, etc) is
|
38
|
+
handled automatically
|
39
|
+
|
40
|
+
## Why a gem for such a trivial task?
|
41
|
+
|
42
|
+
Because i kept copying the same configuration over and over across every
|
43
|
+
application, sometimes leading to errors only discovered in production
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'action_mailer_provider/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "action_mailer_provider"
|
8
|
+
spec.version = ActionMailerProvider::VERSION
|
9
|
+
spec.authors = ["Miguel Palhas"]
|
10
|
+
spec.email = ["mpalhas@gmail.com"]
|
11
|
+
spec.description = %q{Action Mailer configuration helper}
|
12
|
+
spec.summary = %q{Configure Action Mailer gem according to your email provider specs (Google, Zoho Mail, etc)}
|
13
|
+
spec.homepage = "https://github.com/naps62/action_mailer_provider"
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "actionmailer"
|
25
|
+
spec.add_dependency "rails"
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'action_mailer_provider/strategies'
|
2
|
+
|
3
|
+
module ActionMailerProvider
|
4
|
+
class Configuration
|
5
|
+
ATTRIBUTES = [:provider, :domain, :default_email, :default_email_password]
|
6
|
+
attr_accessor(*ATTRIBUTES)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def attributes
|
12
|
+
Hash[ATTRIBUTES.map { |attr| [attr, public_send(attr)] }]
|
13
|
+
end
|
14
|
+
|
15
|
+
def reload
|
16
|
+
strategy = ActionMailerProvider::Strategies.for(provider)
|
17
|
+
strategy.new(attributes).configure if strategy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_accessor :config
|
23
|
+
|
24
|
+
def configure(&block)
|
25
|
+
config ||= Configuration.new
|
26
|
+
yield config if block_given?
|
27
|
+
config.reload
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'action_mailer_provider/strategies/zoho'
|
2
|
+
require 'action_mailer_provider/strategies/gmail'
|
3
|
+
|
4
|
+
module ActionMailerProvider
|
5
|
+
module Strategies
|
6
|
+
def self.for(provider)
|
7
|
+
if provider
|
8
|
+
const = mapping(provider)
|
9
|
+
const_get(const) if const_defined?(const)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def self.mapping(provider)
|
16
|
+
provider.to_s.split('_').map { |w| w.capitalize }.join.to_sym
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActionMailerProvider
|
2
|
+
module Strategies
|
3
|
+
class AbstractSmtpStrategy
|
4
|
+
attr_reader :attributes
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@attributes = attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
def configure
|
11
|
+
ActionMailer::Base.smtp_settings = defaults.merge(configuration)
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
raise 'AbstractStrategy called for ActionMailerProvider'
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def defaults
|
21
|
+
{
|
22
|
+
domain: attributes[:domain],
|
23
|
+
user_name: attributes[:default_email],
|
24
|
+
password: attributes[:default_email_password],
|
25
|
+
authentication: :plain,
|
26
|
+
enable_starttls_auto: true
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'action_mailer_provider/strategies/abstract_smtp_strategy'
|
2
|
+
|
3
|
+
module ActionMailerProvider
|
4
|
+
module Strategies
|
5
|
+
class Gmail < AbstractSmtpStrategy
|
6
|
+
def configuration
|
7
|
+
{
|
8
|
+
address: 'smtp.gmail.com',
|
9
|
+
port: 587
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'action_mailer_provider/strategies/abstract_smtp_strategy'
|
2
|
+
|
3
|
+
module ActionMailerProvider
|
4
|
+
module Strategies
|
5
|
+
class Zoho < AbstractSmtpStrategy
|
6
|
+
def configuration
|
7
|
+
{
|
8
|
+
address: 'smtp.zoho.com',
|
9
|
+
port: 465,
|
10
|
+
ssl: true,
|
11
|
+
tls: true
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module ActionMailerProvider
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path '../templates', __FILE__
|
7
|
+
|
8
|
+
def install
|
9
|
+
set_defaults
|
10
|
+
if yes?('By default, values will be fetched through env variables. Would you like to customize them instead? [yN]')
|
11
|
+
override_default(:provider, 'What provider would you like to use?')
|
12
|
+
override_default(:domain, 'What\'s your email domain?')
|
13
|
+
override_default(:email, 'What\'s the email address to use?')
|
14
|
+
override_default(:password, 'Email password')
|
15
|
+
end
|
16
|
+
template 'initializer.rb.erb', 'config/initializers/action_mailer_provider.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_accessor :provider, :domain, :email, :password
|
22
|
+
|
23
|
+
def quote(str)
|
24
|
+
"'#{str}'"
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_defaults
|
28
|
+
@provider = "ENV['EMAIL_PROVIDER']"
|
29
|
+
@domain = "ENV['EMAIL_DOMAIN']"
|
30
|
+
@email = "ENV['EMAIL_USERNAME']"
|
31
|
+
@password = "ENV['EMAIL_PASSWORD']"
|
32
|
+
end
|
33
|
+
|
34
|
+
def override_default(attr, question)
|
35
|
+
new_value = ask("#{question} [#{public_send(attr)}]")
|
36
|
+
if new_value.size > 0
|
37
|
+
public_send("#{attr}=", quote(new_value))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ActionMailerProvider.configure do |config|
|
2
|
+
# Set your provider here
|
3
|
+
# accepted options:
|
4
|
+
# :zoho
|
5
|
+
# :gmail
|
6
|
+
# nil (to disable the gem)
|
7
|
+
config.provider = <%= @provider %>
|
8
|
+
|
9
|
+
# Your email domain
|
10
|
+
config.domain = <%= @domain %>
|
11
|
+
|
12
|
+
# set the default email account used by action mailer
|
13
|
+
# must belong to the selected provider
|
14
|
+
config.default_email = <%= @email %>
|
15
|
+
|
16
|
+
# password of the email account defined above
|
17
|
+
config.default_email_password = <%= @password %>
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action_mailer_provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miguel Palhas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionmailer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Action Mailer configuration helper
|
70
|
+
email:
|
71
|
+
- mpalhas@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- action_mailer_provider.gemspec
|
82
|
+
- lib/action_mailer_provider.rb
|
83
|
+
- lib/action_mailer_provider/configuration.rb
|
84
|
+
- lib/action_mailer_provider/strategies.rb
|
85
|
+
- lib/action_mailer_provider/strategies/abstract_smtp_strategy.rb
|
86
|
+
- lib/action_mailer_provider/strategies/gmail.rb
|
87
|
+
- lib/action_mailer_provider/strategies/zoho.rb
|
88
|
+
- lib/action_mailer_provider/version.rb
|
89
|
+
- lib/generators/action_mailer_provider/install_generator.rb
|
90
|
+
- lib/generators/action_mailer_provider/templates/initializer.rb.erb
|
91
|
+
homepage: https://github.com/naps62/action_mailer_provider
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.1.11
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Configure Action Mailer gem according to your email provider specs (Google,
|
115
|
+
Zoho Mail, etc)
|
116
|
+
test_files: []
|