padrino-mailer 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,96 @@
1
1
  = padrino-mailer
2
2
 
3
- Description goes here.
3
+ This component uses an enhanced version of the excellent <tt>pony</tt> library (vendored) for a powerful but simple
4
+ mailer system within Sinatra. There is full support for using an html content type as well as for file attachments.
5
+ The MailerPlugin has many similarities to ActionMailer but is much lighterweight and (arguably) easier to use.
6
+
7
+ == Installation
8
+
9
+ To install the 'full-stack' padrino framework, simply grab the latest version from gemcutter:
10
+
11
+ $ sudo gem install padrino --source http://gemcutter.org
12
+
13
+ This will install the necessary padrino gems to get you started.
14
+ Now you are ready to use this gem to enhance your sinatra projects or to create new Padrino applications.
15
+
16
+ You can also install only the padrino-mailer gem for more fine-grained use:
17
+
18
+ $ sudo gem install padrino-mailer --source http://gemcutter.org
19
+
20
+ == Usage
21
+
22
+ Let's take a look at using the MailerPlugin in an application. By default, MailerPlugin uses the built-in sendmail
23
+ functionality on the server. However, smtp is also supported using the following configuration:
24
+
25
+ SinatraMore::MailerBase.smtp_settings = {
26
+ :host => 'smtp.gmail.com',
27
+ :port => '587',
28
+ :tls => true,
29
+ :user => 'user',
30
+ :pass => 'pass',
31
+ :auth => :plain
32
+ }
33
+
34
+ Once those have been defined, the default will become smtp delivery unless overwritten in an individual mail definition.
35
+ Next, we should define a custom mailer extended from <tt>SinatraMore::MailerBase</tt>.
36
+
37
+ # app/mailers/sample_mailer.rb
38
+ class SampleMailer < SinatraMore::MailerBase
39
+ def registration_email(name, user_email_address)
40
+ from 'admin@site.com'
41
+ to user_email_address
42
+ subject 'Welcome to the site!'
43
+ body :name => name
44
+ type 'html' # optional, defaults to plain/text
45
+ charset 'windows-1252' # optional, defaults to utf-8
46
+ via :sendmail # optional, to smtp if defined otherwise sendmail
47
+ end
48
+ end
49
+
50
+ This defines a mail called '<tt>registration_mail</tt>' with the specified attributes for delivery. The <tt>body</tt> method
51
+ is passing the <tt>name</tt> attribute to the body message template which should be defined in
52
+ <tt>[views_path]/sample_mailer/registration_email.erb</tt> as shown below:
53
+
54
+ # ./views/sample_mailer/registration_email.erb
55
+ This is the body of the email and can access the <%= name %> that was passed in from the mailer definition
56
+ That's all there is to defining the body of the email which can be plain text or html
57
+
58
+ Once the mailer definition has been completed and the template has been defined, the email can be sent using:
59
+
60
+ SampleMailer.deliver(:registration_email, "Bob", "bob@bobby.com")
61
+
62
+ or if you like the method_missing approach:
63
+
64
+ SampleMailer.deliver_registration_email "Bob", 'bob@bobby.com'
65
+
66
+ And that will then deliver the email according the the configured options. This is really all you need to send emails.
67
+ A few variations are shown below for completeness.
68
+
69
+ If we want to attach files to our email:
70
+
71
+ # app/mailers/sample_mailer.rb
72
+ class SampleMailer < SinatraMore::MailerBase
73
+ def attachment_email(name, user_email_address)
74
+ from 'admin@site.com'
75
+ to user_email_address
76
+ # ...
77
+ attachments { "foo.zip" => File.read("path/to/foo.zip"), "file.txt" => "this is a text file!" }
78
+ end
79
+ end
80
+
81
+ or perhaps we want to have a short body without the need for a template file:
82
+
83
+ # app/mailers/sample_mailer.rb
84
+ class SampleMailer < SinatraMore::MailerBase
85
+ def short_email(name, user_email_address)
86
+ from 'admin@site.com'
87
+ to user_email_address
88
+ subject 'Welcome to the site!'
89
+ body "This is a short body defined right in the mailer itself"
90
+ end
91
+ end
92
+
93
+ See the wiki article for additional information: <...WIKI...>
4
94
 
5
95
  == Copyright
6
96
 
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/padrino/padrino-mailer"
12
12
  gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
13
13
  gem.add_runtime_dependency "sinatra", ">= 0.9.2"
14
+ gem.add_runtime_dependency "padrino-core", ">= 0.1.1"
14
15
  gem.add_runtime_dependency "tilt", ">= 0.2"
15
16
  gem.add_development_dependency "shoulda", ">= 0"
16
17
  gem.add_development_dependency "haml", ">= 2.2.1"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-mailer}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2009-11-17}
12
+ s.date = %q{2009-11-18}
13
13
  s.description = %q{Mailer system for padrino allowing easy delivery of application emails}
14
14
  s.email = %q{nesquena@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
52
52
 
53
53
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
54
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
55
+ s.add_runtime_dependency(%q<padrino-core>, [">= 0.1.1"])
55
56
  s.add_runtime_dependency(%q<tilt>, [">= 0.2"])
56
57
  s.add_development_dependency(%q<shoulda>, [">= 0"])
57
58
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
@@ -60,6 +61,7 @@ Gem::Specification.new do |s|
60
61
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
61
62
  else
62
63
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
64
+ s.add_dependency(%q<padrino-core>, [">= 0.1.1"])
63
65
  s.add_dependency(%q<tilt>, [">= 0.2"])
64
66
  s.add_dependency(%q<shoulda>, [">= 0"])
65
67
  s.add_dependency(%q<haml>, [">= 2.2.1"])
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
69
71
  end
70
72
  else
71
73
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
74
+ s.add_dependency(%q<padrino-core>, [">= 0.1.1"])
72
75
  s.add_dependency(%q<tilt>, [">= 0.2"])
73
76
  s.add_dependency(%q<shoulda>, [">= 0"])
74
77
  s.add_dependency(%q<haml>, [">= 2.2.1"])
@@ -11,12 +11,13 @@ class MailerDemo < Sinatra::Base
11
11
  :user => 'user',
12
12
  :pass => 'pass',
13
13
  :auth => :plain
14
- }
14
+ }
15
15
  end
16
-
16
+
17
17
  register Padrino::Mailer
18
-
19
- class SampleMailer < Padrino::Mailer::Base
18
+
19
+ class SampleMailer < Padrino::Mailer::Base
20
+
20
21
  def birthday_message(name, age)
21
22
  subject "Happy Birthday!"
22
23
  to 'john@fake.com'
@@ -24,7 +25,7 @@ class MailerDemo < Sinatra::Base
24
25
  body 'name' => name, 'age' => age
25
26
  via :smtp
26
27
  end
27
-
28
+
28
29
  def anniversary_message(names, years_married)
29
30
  subject "Happy anniversary!"
30
31
  to 'julie@fake.com'
@@ -33,12 +34,12 @@ class MailerDemo < Sinatra::Base
33
34
  type 'html'
34
35
  end
35
36
  end
36
-
37
+
37
38
  post "/deliver/plain" do
38
39
  result = SampleMailer.deliver_birthday_message("Joey", 21)
39
40
  result ? "mail delivered" : 'mail not delivered'
40
41
  end
41
-
42
+
42
43
  post "/deliver/html" do
43
44
  result = SampleMailer.deliver_anniversary_message("Joey & Charlotte", 16)
44
45
  result ? "mail delivered" : 'mail not delivered'
@@ -46,5 +47,5 @@ class MailerDemo < Sinatra::Base
46
47
  end
47
48
 
48
49
  class MailerUser
49
-
50
- end
50
+
51
+ end
@@ -7,7 +7,10 @@ class TestPadrinoMailer < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  context 'for mail delivery in sample application' do
10
- setup { MailerDemo::SampleMailer.smtp_settings = MailerDemo.smtp_settings }
10
+ setup {
11
+ Padrino::Mailer::Base::views_path = MailerDemo.views
12
+ MailerDemo::SampleMailer.smtp_settings = MailerDemo.smtp_settings
13
+ }
11
14
 
12
15
  should 'be able to deliver plain text emails' do
13
16
  assert_email_sent(:to => 'john@fake.com', :from => 'noreply@birthday.com', :via => :smtp,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-11-17 00:00:00 -08:00
15
+ date: 2009-11-18 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -25,6 +25,16 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.2
27
27
  version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: padrino-core
30
+ type: :runtime
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.1.1
37
+ version:
28
38
  - !ruby/object:Gem::Dependency
29
39
  name: tilt
30
40
  type: :runtime