sgmailer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/sgmailer +15 -0
- data/lib/sgmailer.rb +175 -0
- metadata +47 -0
data/bin/sgmailer
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'sgmailer'
|
|
2
|
+
first_rg = ARGV[0]
|
|
3
|
+
|
|
4
|
+
if (first_rg == "generate")
|
|
5
|
+
puts SGmailer.generate(ARGV[1], ARGV[2], ARGV)
|
|
6
|
+
elsif (first_rg == "--help")
|
|
7
|
+
puts "Commands:"
|
|
8
|
+
puts "sgmailer generate [username] [password] ([flags])"
|
|
9
|
+
puts "\tusername: your gmail username"
|
|
10
|
+
puts "\tpassword: your gmail password"
|
|
11
|
+
puts "\tflags:\n\t\t--no-plain: Do not include plain-text template in email"
|
|
12
|
+
puts "\n\t\t--no-html: Do not include HTML template in email"
|
|
13
|
+
else
|
|
14
|
+
puts "Error, unrecognized command. Please type in 'sgmailer --help' for help."
|
|
15
|
+
end
|
data/lib/sgmailer.rb
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
class SGmailer
|
|
2
|
+
def self.generate username, password, args
|
|
3
|
+
|
|
4
|
+
if !(username.nil? || password.nil?)
|
|
5
|
+
|
|
6
|
+
helper = Thingies.new(username, password, args)
|
|
7
|
+
|
|
8
|
+
#Check to see if there if the gmailer file already exists
|
|
9
|
+
puts "\tChecking files..."
|
|
10
|
+
|
|
11
|
+
if !helper.check_files?
|
|
12
|
+
puts "\tError, you already have an emailer system in place. Please remove all traces of the emailer system before generating a new one."
|
|
13
|
+
return false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
puts "\tReady to go!"
|
|
17
|
+
#Add email info to the end of environment.rb
|
|
18
|
+
file = File.open("config/environment.rb", "a")
|
|
19
|
+
file.puts helper.get_text(:environment)
|
|
20
|
+
file.close
|
|
21
|
+
|
|
22
|
+
puts "\tModified config/environment.rb"
|
|
23
|
+
|
|
24
|
+
#Generate file for mailer
|
|
25
|
+
if (!File.directory? "app/mailers")
|
|
26
|
+
Dir.mkdir("app/mailers", 755)
|
|
27
|
+
puts "\tCreated mailer directory"
|
|
28
|
+
end
|
|
29
|
+
file = File.new("app/mailers/sgmailer.rb", "w")
|
|
30
|
+
file.puts helper.get_text(:emailer)
|
|
31
|
+
file.close
|
|
32
|
+
puts "\tAdded Mailer in app/mailers/sgmailer.rb"
|
|
33
|
+
|
|
34
|
+
#Add require in application controller
|
|
35
|
+
file = File.open("app/controllers/application_controller.rb", "r")
|
|
36
|
+
ac = ""
|
|
37
|
+
while line = file.gets
|
|
38
|
+
ac = ac + line
|
|
39
|
+
end
|
|
40
|
+
file.close()
|
|
41
|
+
file = File.open("app/controllers/application_controller.rb", "w+")
|
|
42
|
+
file.puts "require 'SGmailer'"
|
|
43
|
+
file.puts ac
|
|
44
|
+
file.close
|
|
45
|
+
puts "\tModified application controller to require SGmailer throughout your application"
|
|
46
|
+
|
|
47
|
+
#Generate email scaffolds
|
|
48
|
+
if (!File.directory? "app/views/s_gmailer")
|
|
49
|
+
Dir.mkdir("app/views/s_gmailer")
|
|
50
|
+
puts "\tCreated views/s_gmailer directory"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
file = File.new("app/views/s_gmailer/email_plain.html.erb", "w")
|
|
54
|
+
file.puts helper.get_text(:plain)
|
|
55
|
+
file.close
|
|
56
|
+
puts "\tAdded plain text email scaffold in app/views/sgmailer/email_plain.html.erb"
|
|
57
|
+
|
|
58
|
+
file = File.new("app/views/s_gmailer/email_html.html.erb", "w")
|
|
59
|
+
file.puts helper.get_text(:html)
|
|
60
|
+
file.close
|
|
61
|
+
puts "\tAdded HTML scaffold in app/views/sgmailer/email_html.html.erb"
|
|
62
|
+
|
|
63
|
+
puts "\nComplete! Edit the email scaffolds with your email (and dynamic text)."
|
|
64
|
+
puts "To send an email, in the controller use: SGmailer.email([to address], [subject]).deliver"
|
|
65
|
+
|
|
66
|
+
else
|
|
67
|
+
puts "\tError. Please put your gmail username and password."
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class SGmailer::Thingies
|
|
74
|
+
|
|
75
|
+
def initialize(username, password, args)
|
|
76
|
+
@username = username
|
|
77
|
+
@password = password
|
|
78
|
+
@args = args
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def check_files?
|
|
82
|
+
#Environment
|
|
83
|
+
if !File.exists? "config/environment.rb"
|
|
84
|
+
return false
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
file = File.open("config/environment.rb", "r")
|
|
88
|
+
ex = false
|
|
89
|
+
file.each do |line|
|
|
90
|
+
if line.include? "ActionMailer::Base.delivery_method = :smtp"
|
|
91
|
+
ex = true
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
if ex == true
|
|
96
|
+
return false
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
#Check for directory
|
|
100
|
+
if File.directory? "app/mailers"
|
|
101
|
+
if File.exists? "app/mailers/s_gmailer.rb"
|
|
102
|
+
return false
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
#Check for templates
|
|
107
|
+
if ((File.exists? "app/views/s_gmailer/email_plain.html.erb") || (File.exists? "app/views/s_gmailer/email_html.html.erb"))
|
|
108
|
+
return false
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
true
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def get_text(text)
|
|
117
|
+
if (text == :environment)
|
|
118
|
+
"
|
|
119
|
+
|
|
120
|
+
ActionMailer::Base.delivery_method = :smtp
|
|
121
|
+
|
|
122
|
+
ActionMailer::Base.raise_delivery_errors = true
|
|
123
|
+
ActionMailer::Base.perform_deliveries = true
|
|
124
|
+
|
|
125
|
+
ActionMailer::Base.smtp_settings = {
|
|
126
|
+
:address => \"smtp.gmail.com\",
|
|
127
|
+
:port => 587,
|
|
128
|
+
:authentication => :plain,
|
|
129
|
+
:user_name => \"" + @username + "\",
|
|
130
|
+
:password => \"" + @password + "\",
|
|
131
|
+
:enable_starttls_auto => true,
|
|
132
|
+
:openssl_verify_mode => \"none\"
|
|
133
|
+
}"
|
|
134
|
+
|
|
135
|
+
elsif (text == :emailer)
|
|
136
|
+
rt = "class SGmailer < ActionMailer::Base
|
|
137
|
+
default :from => \"#{@username}\"
|
|
138
|
+
def email(recipient, subject)
|
|
139
|
+
mail(:to => recipient, :subject => subject) do |format|
|
|
140
|
+
"
|
|
141
|
+
if !arg_exists?("--no-plain")
|
|
142
|
+
rt = rt + "\t\tformat.text { render \"email_plain.html.erb\" }\n"
|
|
143
|
+
end
|
|
144
|
+
if !arg_exists?("--no-html")
|
|
145
|
+
rt = rt + "\t\tformat.html { render \"email_html.html.erb\" }\n"
|
|
146
|
+
end
|
|
147
|
+
rt = rt + " end
|
|
148
|
+
end
|
|
149
|
+
end"
|
|
150
|
+
|
|
151
|
+
rt
|
|
152
|
+
elsif (text == :plain)
|
|
153
|
+
"This is a sample email.
|
|
154
|
+
Your system works!
|
|
155
|
+
|
|
156
|
+
YIPPEEE!!!!"
|
|
157
|
+
|
|
158
|
+
elsif (text == :html)
|
|
159
|
+
"This is a sample email.</br>
|
|
160
|
+
<span style='color:green'>Your system <b>works!</b></span><br/><br/>
|
|
161
|
+
|
|
162
|
+
YIPEEEEE!!!!"
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def arg_exists? cmd
|
|
168
|
+
@args.each do |a|
|
|
169
|
+
if a == cmd
|
|
170
|
+
return true
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
false
|
|
174
|
+
end
|
|
175
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sgmailer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Nolan Blew
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: Allows developers to send simple emails through GMail in Ruby on Rails
|
|
15
|
+
email: nolanblew@hotmail.com
|
|
16
|
+
executables:
|
|
17
|
+
- sgmailer
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- lib/sgmailer.rb
|
|
22
|
+
- bin/sgmailer
|
|
23
|
+
homepage: http://rubygems.org/gems/sgmailer
|
|
24
|
+
licenses: []
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
none: false
|
|
31
|
+
requirements:
|
|
32
|
+
- - ! '>='
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
none: false
|
|
37
|
+
requirements:
|
|
38
|
+
- - ! '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
requirements: []
|
|
42
|
+
rubyforge_project:
|
|
43
|
+
rubygems_version: 1.8.24
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 3
|
|
46
|
+
summary: Generate simple scaffolds for sending emails through GMail
|
|
47
|
+
test_files: []
|