easymailer 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +49 -9
- data/lib/easymailer.rb +2 -143
- data/lib/easymailer/version.rb +1 -1
- data/lib/generators/easymailer/USAGE +8 -0
- data/lib/generators/easymailer/easymailer_generator.rb +17 -0
- data/lib/generators/easymailer/templates/email_controller.rb +29 -0
- data/lib/generators/easymailer/templates/send_email.html.erb +39 -0
- data/lib/generators/easymailer/templates/send_mail.text.erb +1 -0
- data/lib/generators/easymailer/templates/setup_mail.rb +9 -0
- data/lib/generators/easymailer/templates/user_mailer.rb +12 -0
- data/versions.txt +32 -0
- metadata +12 -5
- data/README.txt +0 -41
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Easymailer
|
2
2
|
|
3
|
-
|
3
|
+
Easymailer gem is used to create demo mailer application instantly.This gem is usefull for those who creating a mailer
|
4
|
+
applications from scratch.This will automatically generate ActionMailer scripts and files.This will also create a demo
|
5
|
+
page for you to start simply sending mails in a smart and faster way.This is used in all Rails3.2 version applications
|
6
|
+
and mainly usefull for rails startups which removes the headache of scripting stuff..
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -14,16 +17,53 @@ And then execute:
|
|
14
17
|
|
15
18
|
Or install it yourself as:
|
16
19
|
|
17
|
-
$ gem install easymailer
|
20
|
+
$ gem install easymailer or gem install easymailer -v=2.0.0
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
step1 : gem install easymailer
|
22
25
|
|
23
|
-
|
26
|
+
step2 : place below line in your gem file
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
gem 'easymailer', :git => 'git://github.com/harishkumar/easymailer.git'
|
29
|
+
|
30
|
+
step3 : bundle install
|
31
|
+
|
32
|
+
step4 : rails g easymailer
|
33
|
+
|
34
|
+
step5:
|
35
|
+
|
36
|
+
Change the settings in config/initializers/setup_mail.rb
|
37
|
+
(for Gmail change username and password) which is created auomatically.
|
38
|
+
now start your Application!
|
39
|
+
|
40
|
+
step6:
|
41
|
+
|
42
|
+
Go to link http://localhost:3000/email/send_email or YourIP/email/send_email
|
43
|
+
|
44
|
+
##More Features
|
45
|
+
you can use independently this gem APIs to send mail and change configuration on the fly
|
46
|
+
To send Email -
|
47
|
+
Easymailer.send_mail(message,email,subject,attachment_path,attachment_file_name)
|
48
|
+
|
49
|
+
To change config (example sender id and using another mail vendor apart from gmail)
|
50
|
+
Easymailer.mail_settings(address,port,domain,username,password)
|
51
|
+
Note: for Easymailer.mail_settings Api while using this the session will stored with same domain and username and
|
52
|
+
password to change this again you need to use the same api
|
53
|
+
|
54
|
+
example:
|
55
|
+
First you need to use below api if you dont want to use default ActionMailer settings
|
56
|
+
|
57
|
+
Easymailer.mail_settings(address,port,domain,new_username,password) # now in next line use the below code which will
|
58
|
+
send by using this new_username..
|
59
|
+
|
60
|
+
Easymailer.send_mail(message,email,subject,attachment_path,attachment_file_name)
|
61
|
+
|
62
|
+
Now the session will be of this new username and if you want to change sender username then again use mail_settings Api or to use default settings restart your application.
|
63
|
+
|
64
|
+
|
65
|
+
##Limitations
|
66
|
+
|
67
|
+
Only works for Rails3.2 or above applications..
|
68
|
+
|
69
|
+
Link: https://rubygems.org/gems/easymailer
|
data/lib/easymailer.rb
CHANGED
@@ -1,149 +1,7 @@
|
|
1
1
|
require "easymailer/version"
|
2
2
|
|
3
3
|
module Easymailer
|
4
|
-
|
5
|
-
if File.file?( "#{Rails.root}/config/initializers/setup_mail.rb" )
|
6
|
-
return "Mailer exists..please the settings in config/initializers/setup_mail.rb and restart your application!"
|
7
|
-
else
|
8
|
-
|
9
|
-
File.open("#{Rails.root}/app/mailers/user_mailer.rb", 'w+') do |file|
|
10
|
-
file.syswrite(self.usermailer_text)
|
11
|
-
end
|
12
|
-
|
13
|
-
Dir.mkdir( "#{Rails.root}/app/views/user_mailer")
|
14
|
-
Dir.mkdir( "#{Rails.root}/tmp/uploads")
|
15
|
-
Dir.mkdir( "#{Rails.root}/app/views/email")
|
16
|
-
|
17
|
-
File.open("#{Rails.root}/app/views/user_mailer/send_mail.text.erb", 'w+') do |file|
|
18
|
-
file.syswrite("<%=@message%>")
|
19
|
-
end
|
20
|
-
|
21
|
-
File.open("#{Rails.root}/config/initializers/setup_mail.rb", 'w+') do |file|
|
22
|
-
file.syswrite(self.setup_mail)
|
23
|
-
end
|
24
|
-
|
25
|
-
File.open("#{Rails.root}/app/controllers/email_controller.rb", 'w+') do |file|
|
26
|
-
file.syswrite(self.email_controller)
|
27
|
-
end
|
28
|
-
|
29
|
-
File.open("#{Rails.root}/app/views/email/send_email.html.erb", 'w+') do |file|
|
30
|
-
file.syswrite(self.send_email_view)
|
31
|
-
end
|
32
|
-
|
33
|
-
at_line=3
|
34
|
-
File.open("#{Rails.root}/config/routes.rb",'r+') do |file|
|
35
|
-
while (at_line-=1) > 0 # read up to the line you want to write after
|
36
|
-
file.readline
|
37
|
-
end
|
38
|
-
pos = file.pos # save your position in the file
|
39
|
-
rest = file.read # save the rest of the file
|
40
|
-
file.seek pos # go back to the old position
|
41
|
-
file.write ["\n match 'email/send_email'=>'email#send_email' \n", rest] # write new data & rest of file
|
42
|
-
end
|
43
|
-
return "Mailer created Sucessfully.Change the settings in config/initializers/setup_mail.rb and restart your Application!"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.usermailer_text
|
48
|
-
@name='attachments["#{file_name}"] = File.read(path)'
|
49
|
-
"class UserMailer < ActionMailer::Base
|
50
|
-
default :from => 'eabyas.notifier@gmail.com'
|
51
|
-
def send_mail(message,email,subject,path,file_name)
|
52
|
-
@message=message
|
53
|
-
unless path.nil?
|
54
|
-
#{@name}
|
55
|
-
end
|
56
|
-
mail(:to => email,:subject => subject)
|
57
|
-
end
|
58
|
-
end"
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.setup_mail
|
62
|
-
"ActionMailer::Base.smtp_settings = {
|
63
|
-
:address => 'smtp.gmail.com',
|
64
|
-
:port => 587,
|
65
|
-
:domain => 'gmail.com',
|
66
|
-
:user_name => 'notifier@gmail.com', #Your user name
|
67
|
-
:password => 'password', # Your password
|
68
|
-
:authentication => 'plain',
|
69
|
-
:enable_starttls_auto => true
|
70
|
-
}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.email_controller
|
74
|
-
"class EmailController < ApplicationController
|
75
|
-
require 'easymailer'
|
76
|
-
def send_email
|
77
|
-
if request.post?
|
78
|
-
unless params[:email][:to].nil? or params[:email][:to].blank?
|
79
|
-
to_mail=params[:email][:to]
|
80
|
-
subject=params[:email][:subject]
|
81
|
-
message=params[:email][:message]
|
82
|
-
attachment=params[:email][:file]
|
83
|
-
|
84
|
-
unless attachment.nil? and attachment.blank?
|
85
|
-
file_name=attachment.original_filename
|
86
|
-
dir='/home/harish/september_12/Learning_Rails3/ocean_layout/tmp/uploads/'
|
87
|
-
path=File.join(dir,file_name)
|
88
|
-
File.open(path,'w+')
|
89
|
-
File.open(path, 'wb') { |f| f.write(attachment.read) }
|
90
|
-
|
91
|
-
Easymailer.send_mail(message,to_mail,subject,path,file_name).deliver
|
92
|
-
File.delete(path)
|
93
|
-
else
|
94
|
-
Easymailer.send_mail(message,to_mail,subject,nil,nil).deliver
|
95
|
-
end
|
96
|
-
flash[:notice]='Email Sent Sucesssfully'
|
97
|
-
else
|
98
|
-
flash[:notice]='Please enter Email Id..!'
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end"
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.send_email_view
|
106
|
-
"<%=form_for :email,:html => { :multipart => true } do |f|%>
|
107
|
-
<table>
|
108
|
-
<tr><th><h2>Send Email</h2></th></tr>
|
109
|
-
<tr><td>Mail To</td><td><%=f.text_field :to%></td></tr>
|
110
|
-
<tr><td>Subject</td><td><%=f.text_field :subject%></td></tr>
|
111
|
-
<tr><td>Message</td><td><%=f.text_area :message,:rows=>7,:cols=>40%></td></tr>
|
112
|
-
<tr><td>Attachment</td><td><%=f.file_field :file%></td></tr>
|
113
|
-
<tr><td colspan='2'><%=f.submit 'Send email'%></td></tr>
|
114
|
-
</table>
|
115
|
-
<%end%>
|
116
|
-
<div id='flash' style='display:none;'>Sending Mail Please Wait..</div>
|
117
|
-
<%unless flash[:notice].nil?%>
|
118
|
-
<div class='notice'><p><%=flash[:notice]%><%flash[:notice]=nil%></p></div>
|
119
|
-
<%end%>
|
120
|
-
|
121
|
-
<style type='text/css'>
|
122
|
-
#flash{
|
123
|
-
background:#ECC3C3;font-size:14px;
|
124
|
-
border: 1px solid #A9A9A9;
|
125
|
-
text-align:center;
|
126
|
-
width:800px;
|
127
|
-
margin:0px auto;
|
128
|
-
}
|
129
|
-
.notice{background:#99FF99;font-size:14px;
|
130
|
-
border: 1px solid #A9A9A9;
|
131
|
-
text-align:center;
|
132
|
-
width:800px;
|
133
|
-
margin:0px auto;
|
134
|
-
}
|
135
|
-
</style>
|
136
|
-
|
137
|
-
<script type='text/javascript'>
|
138
|
-
$(document).ready(function(){
|
139
|
-
$('form').submit(function(){
|
140
|
-
$('#flash').css('display','block');
|
141
|
-
$('.notice').css('display','none');
|
142
|
-
});
|
143
|
-
});
|
144
|
-
</script>"
|
145
|
-
end
|
146
|
-
|
4
|
+
|
147
5
|
def self.send_mail(message,email,subject,path,file_name)
|
148
6
|
if File.file?( "#{Rails.root}/config/initializers/setup_mail.rb" )
|
149
7
|
UserMailer.send_mail(message,email,subject,path,file_name).deliver
|
@@ -163,4 +21,5 @@ end"
|
|
163
21
|
:enable_starttls_auto => true
|
164
22
|
}
|
165
23
|
end
|
24
|
+
|
166
25
|
end
|
data/lib/easymailer/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class EasymailerGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
argument :easymailer_name,:type=>:string,:default=>'application'
|
4
|
+
|
5
|
+
def generate_easymailer
|
6
|
+
copy_file 'user_mailer.rb', 'app/mailers/user_mailer.rb'
|
7
|
+
empty_directory "app/views/user_mailer"
|
8
|
+
empty_directory "tmp/uploads"
|
9
|
+
empty_directory "app/views/email"
|
10
|
+
copy_file 'send_mail.text.erb','app/views/user_mailer/send_mail.text.erb'
|
11
|
+
copy_file 'setup_mail.rb','config/initializers/setup_mail.rb'
|
12
|
+
copy_file 'email_controller.rb','app/controllers/email_controller.rb'
|
13
|
+
copy_file 'send_email.html.erb','app/views/email/send_email.html.erb'
|
14
|
+
|
15
|
+
insert_into_file "config/routes.rb", "match 'email/send_email'=>'email#send_email' \n", :after => "Application.routes.draw do\n"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class EmailController < ApplicationController
|
2
|
+
require 'easymailer'
|
3
|
+
def send_email
|
4
|
+
if request.post?
|
5
|
+
unless params[:email][:to].nil? or params[:email][:to].blank?
|
6
|
+
to_mail=params[:email][:to]
|
7
|
+
subject=params[:email][:subject]
|
8
|
+
message=params[:email][:message]
|
9
|
+
attachment=params[:email][:file]
|
10
|
+
|
11
|
+
unless attachment.nil? and attachment.blank?
|
12
|
+
file_name=attachment.original_filename
|
13
|
+
dir="#{Rails.root}/tmp/uploads/"
|
14
|
+
path=File.join(dir,file_name)
|
15
|
+
File.open(path,'w+')
|
16
|
+
File.open(path, 'wb') { |f| f.write(attachment.read) }
|
17
|
+
|
18
|
+
Easymailer.send_mail(message,to_mail,subject,path,file_name).deliver
|
19
|
+
File.delete(path)
|
20
|
+
else
|
21
|
+
Easymailer.send_mail(message,to_mail,subject,nil,nil).deliver
|
22
|
+
end
|
23
|
+
flash[:notice]='Email Sent Sucesssfully'
|
24
|
+
else
|
25
|
+
flash[:notice]='Please enter Email Id..!'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%=form_for :email,:html => { :multipart => true } do |f|%>
|
2
|
+
<table>
|
3
|
+
<tr><th><h2>Send Email</h2></th></tr>
|
4
|
+
<tr><td>Mail To</td><td><%=f.text_field :to%></td></tr>
|
5
|
+
<tr><td>Subject</td><td><%=f.text_field :subject%></td></tr>
|
6
|
+
<tr><td>Message</td><td><%=f.text_area :message,:rows=>7,:cols=>40%></td></tr>
|
7
|
+
<tr><td>Attachment</td><td><%=f.file_field :file%></td></tr>
|
8
|
+
<tr><td colspan='2'><%=f.submit 'Send email'%></td></tr>
|
9
|
+
</table>
|
10
|
+
<%end%>
|
11
|
+
<div id='flash' style='display:none;'>Sending Mail Please Wait..</div>
|
12
|
+
<%unless flash[:notice].nil?%>
|
13
|
+
<div class='notice'><p><%=flash[:notice]%><%flash[:notice]=nil%></p></div>
|
14
|
+
<%end%>
|
15
|
+
|
16
|
+
<style type='text/css'>
|
17
|
+
#flash{
|
18
|
+
background:#ECC3C3;font-size:14px;
|
19
|
+
border: 1px solid #A9A9A9;
|
20
|
+
text-align:center;
|
21
|
+
width:800px;
|
22
|
+
margin:0px auto;
|
23
|
+
}
|
24
|
+
.notice{background:#99FF99;font-size:14px;
|
25
|
+
border: 1px solid #A9A9A9;
|
26
|
+
text-align:center;
|
27
|
+
width:800px;
|
28
|
+
margin:0px auto;
|
29
|
+
}
|
30
|
+
</style>
|
31
|
+
|
32
|
+
<script type='text/javascript'>
|
33
|
+
$(document).ready(function(){
|
34
|
+
$('form').submit(function(){
|
35
|
+
$('#flash').css('display','block');
|
36
|
+
$('.notice').css('display','none');
|
37
|
+
});
|
38
|
+
});
|
39
|
+
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%=@message%>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
ActionMailer::Base.smtp_settings = {
|
2
|
+
:address => 'smtp.gmail.com',
|
3
|
+
:port => 587,
|
4
|
+
:domain => 'gmail.com',
|
5
|
+
:user_name => 'notifier@gmail.com', #Your user name
|
6
|
+
:password => 'password', # Your password
|
7
|
+
:authentication => 'plain',
|
8
|
+
:enable_starttls_auto => true
|
9
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class UserMailer < ActionMailer::Base
|
2
|
+
default :from => 'notifier@gmail.com'
|
3
|
+
|
4
|
+
def send_mail(message,email,subject,path,file_name)
|
5
|
+
@message=message
|
6
|
+
unless path.nil?
|
7
|
+
attachments["#{file_name}"] = File.read(path)
|
8
|
+
end
|
9
|
+
mail(:to => email,:subject => subject)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/versions.txt
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
## Version 1.0.0
|
2
|
+
|
3
|
+
step1 :
|
4
|
+
gem install easymailer
|
5
|
+
|
6
|
+
step2 :
|
7
|
+
place (gem 'easymailer') in your gem file
|
8
|
+
|
9
|
+
step3 :
|
10
|
+
bundle install
|
11
|
+
|
12
|
+
step4:
|
13
|
+
initially in any controller place the Easymailer.create_mailer
|
14
|
+
example:
|
15
|
+
|
16
|
+
app/controllers/demo_controller.rb
|
17
|
+
class DemoController < ApplicationController
|
18
|
+
require 'easymailer'
|
19
|
+
def index
|
20
|
+
@message=Easymailer.create_mailer
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
app/views/index.html.erb
|
25
|
+
<%=@message%>
|
26
|
+
|
27
|
+
if you get message as "Mailer created Sucessfully" Then Change the settings in config/initializers/setup_mail.rb
|
28
|
+
(for Gmail change username and password) which is created auomatically.
|
29
|
+
and restart your Application!
|
30
|
+
|
31
|
+
step5:
|
32
|
+
Go to link http://localhost:3000/email/send_email or YourIP/email/send_email
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easymailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 2
|
7
8
|
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 2.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- harish
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-10-
|
18
|
+
date: 2012-10-05 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: "Easymailer gem is used to create demo mailer application instantly.This gem is very usefull for those who creating a mailer applications from scratch.This will automatically generate ActionMailer scripts and files.This will also create a demo page for you to start simply sending mails in a smart and faster way.This is used in all Rails3.2 version applications and very usefull for rails startups which removes the headache of scripting stuff.. "
|
@@ -32,11 +32,18 @@ files:
|
|
32
32
|
- Gemfile
|
33
33
|
- LICENSE.txt
|
34
34
|
- README.md
|
35
|
-
- README.txt
|
36
35
|
- Rakefile
|
37
36
|
- easymailer.gemspec
|
38
37
|
- lib/easymailer.rb
|
39
38
|
- lib/easymailer/version.rb
|
39
|
+
- lib/generators/easymailer/USAGE
|
40
|
+
- lib/generators/easymailer/easymailer_generator.rb
|
41
|
+
- lib/generators/easymailer/templates/email_controller.rb
|
42
|
+
- lib/generators/easymailer/templates/send_email.html.erb
|
43
|
+
- lib/generators/easymailer/templates/send_mail.text.erb
|
44
|
+
- lib/generators/easymailer/templates/setup_mail.rb
|
45
|
+
- lib/generators/easymailer/templates/user_mailer.rb
|
46
|
+
- versions.txt
|
40
47
|
homepage: ""
|
41
48
|
licenses: []
|
42
49
|
|
data/README.txt
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
Description
|
2
|
-
|
3
|
-
Easymailer gem is used to create demo mailer application instantly.This gem is usefull for those who creating a mailer applications from scratch.This will automatically generate ActionMailer scripts and files.This will also create a demo page for you to start simply sending mails in a smart and faster way.This is used in all Rails3.2 version applications and mainly usefull for rails startups which removes the headache of scripting stuff..
|
4
|
-
|
5
|
-
Installation
|
6
|
-
|
7
|
-
step1 :
|
8
|
-
gem install easymailer
|
9
|
-
|
10
|
-
step2 :
|
11
|
-
place (gem 'easymailer') in your gem file
|
12
|
-
|
13
|
-
step3 :
|
14
|
-
bundle install
|
15
|
-
|
16
|
-
step4:
|
17
|
-
initially in any controller place the Easymailer.create_mailer
|
18
|
-
example:
|
19
|
-
|
20
|
-
app/controllers/demo_controller.rb
|
21
|
-
class DemoController < ApplicationController
|
22
|
-
require 'easy_mailer'
|
23
|
-
def index
|
24
|
-
@message=EasyMailer.create_mailer
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
app/views/index.html.erb
|
29
|
-
<%=@message%>
|
30
|
-
|
31
|
-
if you get message as "Mailer created Sucessfully" Then Change the settings in config/initializers/setup_mail.rb
|
32
|
-
(for Gmail change username and password) which is created auomatically.
|
33
|
-
and restart your Application!
|
34
|
-
|
35
|
-
step5:
|
36
|
-
Go to link http://localhost:3000/email/send_email or YourIP/email/send_email
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|