easyemail 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9a220b8980346e9ac6c59b62eaa2f42601ed821
4
+ data.tar.gz: eb8dbd1b9c262a456aa14b7c3c60a803333269d0
5
+ SHA512:
6
+ metadata.gz: 378e054803df07e7973fc8d31f2b947ca88a5a8ed3e86d742f1af54d1f66f04d00cb32367847da1b0e51d56c84c39c231037425176b9b89acaa3763232609cf3
7
+ data.tar.gz: ea630d6f6647bd74486942902e63bd971a73e8c4cf12dd8efcd6c4871fe0358b08ae6b128eb8fa63fbada6cb1a09b131f82e80be6e2c8ddf8d4aa51ea1aeb46e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ build.sh
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 tuitu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Easyemail
2
+
3
+ Easyemail是一个为简化邮件发送流程而发布的gem.
4
+
5
+ ## Installation
6
+
7
+ `gem install easyemail`
8
+
9
+ ## Usage
10
+
11
+ ### 第一步:设置smtp
12
+
13
+ 该gem为三个知名的邮件服务商`163.com qq.com gmail.com`和我学校(HHU)的邮箱服务做了预先的设置,如果你用来发送邮件的账号来自于以上的邮件服务商,设置smtp的方法如下:
14
+ ```ruby
15
+ # 以163邮箱为例
16
+ # 确保该账号开通了smtp服务
17
+ # username 和 password 是你的邮箱账号(账号包括完整后缀)和密码
18
+ mailer = Easyemail.new
19
+ mailer.smtp_settings_for_163 user_name, password
20
+ # 同样的方法还有:
21
+ # smtp_settings_for_hhu
22
+ # smtp_settings_for_qq
23
+ # smtp_settings_for_gmail
24
+ ```
25
+
26
+ 如果你使用的不是以上任何一种,设置方法如下:
27
+ ```ruby
28
+ # 确保该账号开通了smtp服务
29
+ # username 和 password 是你的邮箱账号(账号包括完整后缀)和密码
30
+ mailer = Easyemail.new
31
+ smtp = {
32
+ "address" => "**",
33
+ "port" => **,
34
+ "authentication" => "**",
35
+ "user_name" => "**",
36
+ "password" => "**",
37
+ "enable_starttls_auto" => **
38
+ }
39
+ mailer.smtp_settings smtp
40
+ ```
41
+
42
+ 另外,还可以从yaml配置文件中导入smtp信息,同样的,如果来自以上四个邮件服务商,配置文件可以这样写
43
+ ```
44
+ provider: ** # (只能从163, qq, gmail, hhu中任选一个)
45
+ user_name: **
46
+ password: **
47
+ ```
48
+ 否则配置文件需这样写:
49
+ ```
50
+ address: **
51
+ port: **
52
+ authentication: **
53
+ user_name: **
54
+ password: **
55
+ enable_starttls_auto: **
56
+ ```
57
+
58
+ 调用代码如下:
59
+ ```ruby
60
+ mailer = Easyemail.new
61
+ mailer.load_smtp_settings_from_yaml file_path
62
+ ```
63
+
64
+ ### 第二步:设置收件人
65
+
66
+ 允许群发邮件, 设置收件人代码如下:
67
+ ```ruby
68
+ mailer.to = "someone@**.com" # 单收件人
69
+ mailer.to = ["someone@**.com", "**"] # 多收件人
70
+ ```
71
+
72
+ ### 第三步:发送邮件
73
+
74
+ 邮件内容支持文本和html格式,两者都以字符串的形式作为参数,调用代码如下:
75
+ ```ruby
76
+ # subject是邮件主题, content是邮件内容
77
+ mailer.email(subject, content)
78
+ ```
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "easyemail"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/easyemail.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easyemail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easyemail"
8
+ spec.version = Easyemail::VERSION
9
+ spec.authors = ["TUITU"]
10
+ spec.email = ["1965972530@qq.com"]
11
+
12
+ spec.summary = %q{"easyemail"}
13
+ spec.description = %q{"send email in a simple way"}
14
+ spec.homepage = "https://github.com/hellotuitu/easyemail."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "yaml"
36
+ spec.add_development_dependency "action_mailer"
37
+ spec.add_development_dependency "active_support"
38
+ end
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
+ </head>
6
+ <body>
7
+ <%= raw @content %>
8
+ </body>
9
+ </html>
File without changes
@@ -0,0 +1,3 @@
1
+ class Easyemail
2
+ VERSION = "0.1.1"
3
+ end
data/lib/easyemail.rb ADDED
@@ -0,0 +1,123 @@
1
+ require "easyemail/version"
2
+
3
+ class Easyemail
4
+ require 'active_support'
5
+ require 'action_mailer'
6
+ require "yaml"
7
+
8
+ ActionMailer::Base.raise_delivery_errors = true
9
+ ActionMailer::Base.perform_deliveries = true
10
+ ActionMailer::Base.delivery_method = :smtp
11
+ ActionMailer::Base.view_paths = File.dirname(__FILE__)
12
+
13
+ class Mailer < ActionMailer::Base
14
+ def send_email from, to, subject, content
15
+ @content = content
16
+ mail(
17
+ to: to,
18
+ from: from,
19
+ subject: subject
20
+ ) do | format |
21
+ format.html
22
+ end
23
+ end
24
+ end
25
+
26
+ def load_smtp_settings_from_yaml path
27
+ smtp = YAML.load_file(path)
28
+ if smtp["provider"]
29
+ # 如果指定了邮件服务商 就直接跳转到该服务商
30
+ # 待选列表 163, hhu, qq, gmail
31
+ self.send("smtp_settings_for_#{smtp["provider"]}", smtp["user_name"], smtp["password"])
32
+ else
33
+ self.smtp_settings smtp
34
+ end
35
+ end
36
+
37
+ def smtp_settings smtp
38
+ # common settings for smtp, all provided by user.
39
+ begin
40
+ ActionMailer::Base.smtp_settings = {
41
+ address: smtp['address'],
42
+ port: smtp["port"],
43
+ authentication: smtp["authentication"],
44
+ user_name: smtp['user_name'],
45
+ password: smtp['password'],
46
+ enable_starttls_auto: smtp["enable_starttls_auto"]
47
+ }
48
+ @from = smtp["user_name"]
49
+ @config = true
50
+ rescue
51
+ raise "wrong parameters for smtp settings."
52
+ end
53
+ end
54
+
55
+ def to= to
56
+ # 支持群发
57
+ @to = to
58
+ end
59
+
60
+ def email subject, content
61
+ # content支持html
62
+
63
+ if @config && @to
64
+ if @to.respond_to? :each
65
+ @to.each do | e |
66
+ Mailer.send_email(@from, e, subject, content).deliver
67
+ end
68
+ else
69
+ Mailer.send_email(@from, @to, subject, content).deliver
70
+ end
71
+ else
72
+ raise "check smtp_settings and receiver!"
73
+ end
74
+ end
75
+
76
+ def smtp_settings_for_163 user_name, password
77
+ smtp = {
78
+ "address" => "smtp.163.com",
79
+ "port" => 25,
80
+ "authentication" => "login",
81
+ "user_name" => user_name,
82
+ "password" => password,
83
+ "enable_starttls_auto" => true
84
+ }
85
+ self.smtp_settings smtp
86
+ end
87
+
88
+ def smtp_settings_for_hhu user_name, password
89
+ smtp = {
90
+ "address" => "mail.hhu.edu.cn",
91
+ "port" => 25,
92
+ "authentication" => "login",
93
+ "user_name" => user_name,
94
+ "password" => password,
95
+ "enable_starttls_auto" => false
96
+ }
97
+ self.smtp_settings smtp
98
+ end
99
+
100
+ def smtp_settings_for_qq user_name, password
101
+ smtp = {
102
+ "address" => "smtp.qq.com",
103
+ "port" => 25,
104
+ "authentication" => "login",
105
+ "user_name" => user_name,
106
+ "password" => password,
107
+ "enable_starttls_auto" => false
108
+ }
109
+ self.smtp_settings smtp
110
+ end
111
+
112
+ def smtp_settings_for_gmail user_name, password
113
+ smtp = {
114
+ "address" => "smtp.gmail.com",
115
+ "port" => 587,
116
+ "authentication" => "login",
117
+ "user_name" => user_name,
118
+ "password" => password,
119
+ "enable_starttls_auto" => true
120
+ }
121
+ self.smtp_settings smtp
122
+ end
123
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easyemail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - TUITU
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-18 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yaml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: action_mailer
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: active_support
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: '"send email in a simple way"'
84
+ email:
85
+ - 1965972530@qq.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - easyemail.gemspec
97
+ - lib/easyemail.rb
98
+ - lib/easyemail/mailer/send_email.html.erb
99
+ - lib/easyemail/mailer/send_email.text.erb
100
+ - lib/easyemail/version.rb
101
+ homepage: https://github.com/hellotuitu/easyemail.
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: '"easyemail"'
126
+ test_files: []