merb-mailer 0.9.2
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/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +52 -0
- data/TODO +5 -0
- data/lib/merb-mailer.rb +3 -0
- data/lib/merb-mailer/mail_controller.rb +328 -0
- data/lib/merb-mailer/mailer.rb +104 -0
- data/lib/merb-mailer/merb_controller.rb +21 -0
- metadata +80 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 YOUR NAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require "spec/rake/spectask"
|
4
|
+
|
5
|
+
PLUGIN = "merb-mailer"
|
6
|
+
NAME = "merb-mailer"
|
7
|
+
VERSION = "0.9.2"
|
8
|
+
AUTHOR = "Yehuda Katz"
|
9
|
+
EMAIL = "wycats@gmail.com"
|
10
|
+
HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-mailer/"
|
11
|
+
SUMMARY = "Merb plugin that provides mailer functionality to Merb"
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = NAME
|
15
|
+
s.version = VERSION
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.has_rdoc = true
|
18
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
19
|
+
s.summary = SUMMARY
|
20
|
+
s.description = s.summary
|
21
|
+
s.author = AUTHOR
|
22
|
+
s.email = EMAIL
|
23
|
+
s.homepage = HOMEPAGE
|
24
|
+
s.add_dependency('merb-core', '>= 0.9.2')
|
25
|
+
s.add_dependency("mailfactory", ">= 1.2.3")
|
26
|
+
s.require_path = 'lib'
|
27
|
+
s.autorequire = PLUGIN
|
28
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
|
29
|
+
end
|
30
|
+
|
31
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
32
|
+
pkg.gem_spec = spec
|
33
|
+
end
|
34
|
+
|
35
|
+
task :install => [:package] do
|
36
|
+
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
|
37
|
+
end
|
38
|
+
|
39
|
+
namespace :jruby do
|
40
|
+
|
41
|
+
desc "Run :package and install the resulting .gem with jruby"
|
42
|
+
task :install => :package do
|
43
|
+
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Run all specs"
|
49
|
+
Spec::Rake::SpecTask.new("specs") do |t|
|
50
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
51
|
+
t.spec_files = Dir["spec/**/*_spec.rb"].sort
|
52
|
+
end
|
data/TODO
ADDED
data/lib/merb-mailer.rb
ADDED
@@ -0,0 +1,328 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
# Sending mail from a controller involves three steps:
|
4
|
+
#
|
5
|
+
# * Set mail settings in merb_init.rb (Not shown here...see the Mailer docs).
|
6
|
+
# * Create a MailController subclass with actions and templates.
|
7
|
+
# * Call the MailController from another Controller via the send_mail method.
|
8
|
+
#
|
9
|
+
# First, create a file in app/mailers that subclasses Merb::MailController.
|
10
|
+
# The actions in this controller will do nothing but render mail.
|
11
|
+
#
|
12
|
+
# # app/mailers/article_mailer.rb
|
13
|
+
# class ArticleMailer < Merb::MailController
|
14
|
+
#
|
15
|
+
# def notify
|
16
|
+
# @user = params[:user]
|
17
|
+
# render_mail
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# You also can access the params hash for values passed with the
|
23
|
+
# Controller.send_mail method. See also the documentation for
|
24
|
+
# render_mail to see all the ways it can be called.
|
25
|
+
#
|
26
|
+
# Create a template in a subdirectory of app/mailers/views that corresponds
|
27
|
+
# to the controller and action name. Put plain text and ERB tags here:
|
28
|
+
#
|
29
|
+
# # app/mailers/views/article_mailer/notify.text.erb
|
30
|
+
# Hey, <%= @user.name %>,
|
31
|
+
#
|
32
|
+
# We're running a sale on dog bones!
|
33
|
+
#
|
34
|
+
# Finally, call the Controller.send_mail method from a standard
|
35
|
+
# Merb controller.
|
36
|
+
#
|
37
|
+
# class Articles < Application
|
38
|
+
#
|
39
|
+
# def index
|
40
|
+
# @user = User.find_by_name('louie')
|
41
|
+
#
|
42
|
+
# send_mail(ArticleMailer, :notify, {
|
43
|
+
# :from => "me@example.com",
|
44
|
+
# :to => "louie@example.com",
|
45
|
+
# :subject => "Sale on Dog Bones!"
|
46
|
+
# }, { :user => @user })
|
47
|
+
# render
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# Note: If you don't pass a fourth argument to Controller.send_mail,
|
53
|
+
# the controller's params will be sent to the MailController subclass
|
54
|
+
# as params. However, you can explicitly send a hash of objects that
|
55
|
+
# will populate the params hash instead. In either case, you must
|
56
|
+
# set instance variables in the MailController's actions if you
|
57
|
+
# want to use them in the MailController's views.
|
58
|
+
#
|
59
|
+
# The MailController class is very powerful. You can:
|
60
|
+
#
|
61
|
+
# * Send multipart email with a single call to render_mail.
|
62
|
+
# * Attach files.
|
63
|
+
# * Render layouts and other templates.
|
64
|
+
# * Use any template engine supported by Merb.
|
65
|
+
|
66
|
+
class MailController < AbstractController
|
67
|
+
|
68
|
+
class_inheritable_accessor :_mailer_klass
|
69
|
+
self._mailer_klass = Merb::Mailer
|
70
|
+
|
71
|
+
attr_accessor :params, :mailer, :mail
|
72
|
+
attr_reader :session, :base_controller
|
73
|
+
|
74
|
+
# ==== Parameters
|
75
|
+
# action<~to_s>:: The name of the action that will be rendered.
|
76
|
+
# type<~to_s>::
|
77
|
+
# The mime-type of the template that will be rendered. Defaults to nil.
|
78
|
+
# controller<~to_s>::
|
79
|
+
# The name of the controller that will be rendered. Defaults to
|
80
|
+
# controller_name.
|
81
|
+
#
|
82
|
+
# ==== Returns
|
83
|
+
# String:: The template location, i.e. ":controller/:action.:type".
|
84
|
+
def _template_location(action, type = nil, controller = controller_name)
|
85
|
+
"#{controller}/#{action}.#{type}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# ==== Parameters
|
89
|
+
# params<Hash>:: Configuration parameters for the MailController.
|
90
|
+
# controller<Merb::Controller>:: The base controller.
|
91
|
+
def initialize(params = {}, controller = nil)
|
92
|
+
@params = params
|
93
|
+
@base_controller = controller
|
94
|
+
@session = (controller && controller.session) || {}
|
95
|
+
super
|
96
|
+
end
|
97
|
+
|
98
|
+
# Sets the template root to the default mailer view directory.
|
99
|
+
#
|
100
|
+
# ==== Parameters
|
101
|
+
# klass<Class>::
|
102
|
+
# The Merb::MailController inheriting from the base class.
|
103
|
+
def self.inherited(klass)
|
104
|
+
super
|
105
|
+
klass.class_eval %{self._template_root = Merb.dir_for(:mailer) / "views"}
|
106
|
+
end
|
107
|
+
|
108
|
+
# Override filters halted to return nothing.
|
109
|
+
def filters_halted
|
110
|
+
end
|
111
|
+
|
112
|
+
# Allows you to render various types of things into the text and HTML parts
|
113
|
+
# of an email If you include just text, the email will be sent as
|
114
|
+
# plain-text. If you include HTML, the email will be sent as a multi-part
|
115
|
+
# email.
|
116
|
+
#
|
117
|
+
# ==== Parameters
|
118
|
+
# options<~to_s, Hash>::
|
119
|
+
# Options for rendering the email or an action name. See examples below
|
120
|
+
# for usage.
|
121
|
+
#
|
122
|
+
# ==== Examples
|
123
|
+
# There are a lot of ways to use render_mail, but it works similarly to the
|
124
|
+
# default Merb render method.
|
125
|
+
#
|
126
|
+
# First of all, you'll need to store email files in your
|
127
|
+
# app/mailers/views directory. They should be under a directory that
|
128
|
+
# matches the name of your mailer (e.g. TestMailer's views would be stored
|
129
|
+
# under test_mailer).
|
130
|
+
#
|
131
|
+
# The files themselves should be named action_name.mime_type.extension. For
|
132
|
+
# example, an erb template that should be the HTML part of the email, and
|
133
|
+
# rendered from the "foo" action would be named foo.html.erb.
|
134
|
+
#
|
135
|
+
# The only mime-types currently supported are "html" and "text", which
|
136
|
+
# correspond to text/html and text/plain respectively. All template systems
|
137
|
+
# supported by your app are available to MailController, and the extensions
|
138
|
+
# are the same as they are throughout the rest of Merb.
|
139
|
+
#
|
140
|
+
# render_mail can take any of the following option patterns:
|
141
|
+
#
|
142
|
+
# render_mail
|
143
|
+
#
|
144
|
+
# will attempt to render the current action. If the current action is
|
145
|
+
# "foo", this is identical to render_mail :foo.
|
146
|
+
#
|
147
|
+
# render_mail :foo
|
148
|
+
#
|
149
|
+
# checks for foo.html.ext and foo.text.ext and applies them as appropriate.
|
150
|
+
#
|
151
|
+
# render_mail :action => {:html => :foo, :text => :bar}
|
152
|
+
#
|
153
|
+
# checks for foo.html.ext and bar.text.ext in the view directory of the
|
154
|
+
# current controller and adds them to the mail object if found
|
155
|
+
#
|
156
|
+
# render_mail :template => {:html => "foo/bar", :text => "foo/baz"}
|
157
|
+
#
|
158
|
+
# checks for bar.html.ext and baz.text.ext in the foo directory and adds
|
159
|
+
# them to the mail object if found.
|
160
|
+
#
|
161
|
+
# render_mail :html => :foo, :text => :bar
|
162
|
+
#
|
163
|
+
# the same as render_mail :action => {html => :foo, :text => :bar }
|
164
|
+
#
|
165
|
+
# render_mail :html => "FOO", :text => "BAR"
|
166
|
+
#
|
167
|
+
# adds the text "FOO" as the html part of the email and the text "BAR" as
|
168
|
+
# the text part of the email. The difference between the last two examples
|
169
|
+
# is that symbols represent actions to render, while string represent the
|
170
|
+
# literal text to render. Note that you can use regular render methods
|
171
|
+
# instead of literal strings here, like:
|
172
|
+
#
|
173
|
+
# render_mail :html => render(:action => :foo)
|
174
|
+
#
|
175
|
+
# but you're probably better off just using render_mail :action at that
|
176
|
+
# point.
|
177
|
+
#
|
178
|
+
# You can also mix and match:
|
179
|
+
#
|
180
|
+
# render_mail :action => {:html => :foo}, :text => "BAR"
|
181
|
+
#
|
182
|
+
# which would be identical to:
|
183
|
+
#
|
184
|
+
# render_mail :html => :foo, :text => "BAR"
|
185
|
+
def render_mail(options = @method)
|
186
|
+
@_missing_templates = false # used to make sure that at least one template was found
|
187
|
+
# If the options are not a hash, normalize to an action hash
|
188
|
+
options = {:action => {:html => options, :text => options}} if !options.is_a?(Hash)
|
189
|
+
|
190
|
+
# Take care of the options
|
191
|
+
opts_hash = {}
|
192
|
+
opts = options.dup
|
193
|
+
actions = opts.delete(:action) if opts[:action].is_a?(Hash)
|
194
|
+
templates = opts.delete(:template) if opts[:template].is_a?(Hash)
|
195
|
+
|
196
|
+
# Prepare the options hash for each format
|
197
|
+
# We need to delete anything relating to the other format here
|
198
|
+
# before we try to render the template.
|
199
|
+
[:html, :text].each do |fmt|
|
200
|
+
opts_hash[fmt] = opts.delete(fmt)
|
201
|
+
opts_hash[fmt] ||= actions[fmt] if actions && actions[fmt]
|
202
|
+
opts_hash[:template] = templates[fmt] if templates && templates[fmt]
|
203
|
+
end
|
204
|
+
|
205
|
+
# Send the result to the mailer
|
206
|
+
{ :html => "rawhtml=", :text => "text="}.each do |fmt,meth|
|
207
|
+
begin
|
208
|
+
local_opts = opts.merge(:format => fmt)
|
209
|
+
local_opts.merge!(:layout => false) if opts_hash[fmt].is_a?(String)
|
210
|
+
|
211
|
+
value = render opts_hash[fmt], local_opts
|
212
|
+
@mail.send(meth,value) unless value.nil? || value.empty?
|
213
|
+
rescue Merb::ControllerExceptions::TemplateNotFound => e
|
214
|
+
# An error should be logged if no template is found instead of an error raised
|
215
|
+
if @_missing_templates
|
216
|
+
Merb.logger.error(e)
|
217
|
+
else
|
218
|
+
@_missing_templates = true
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
@mail
|
223
|
+
end
|
224
|
+
|
225
|
+
# Attaches a file or multiple files to an email. You call this from a
|
226
|
+
# method in your MailController (including a before filter).
|
227
|
+
#
|
228
|
+
# ==== Parameters
|
229
|
+
# file_or_files<File, Array[File]>:: File(s) to attach.
|
230
|
+
# filename<String>::
|
231
|
+
# type<~to_s>::
|
232
|
+
# The attachment MIME type. If left out, it will be determined from
|
233
|
+
# file_or_files.
|
234
|
+
# headers<String, Array>:: Additional attachment headers.
|
235
|
+
#
|
236
|
+
# ==== Examples
|
237
|
+
# attach File.open("foo")
|
238
|
+
# attach [File.open("foo"), File.open("bar")]
|
239
|
+
#
|
240
|
+
# If you are passing an array of files, you should use an array of the
|
241
|
+
# allowed parameters:
|
242
|
+
#
|
243
|
+
# attach [[File.open("foo"), "bar", "text/html"], [File.open("baz"),
|
244
|
+
# "bat", "text/css"]
|
245
|
+
#
|
246
|
+
# which would attach two files ("foo" and "baz" in the filesystem) as
|
247
|
+
# "bar" and "bat" respectively. It would also set the mime-type as
|
248
|
+
# "text/html" and "text/css" respectively.
|
249
|
+
def attach( file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil,
|
250
|
+
type = nil, headers = nil)
|
251
|
+
@mailer.attach(file_or_files, filename, type, headers)
|
252
|
+
end
|
253
|
+
|
254
|
+
# ==== Parameters
|
255
|
+
# method<~to_s>:: The method name to dispatch to.
|
256
|
+
# mail_params<Hash>:: Parameters to send to MailFactory (see below).
|
257
|
+
#
|
258
|
+
# ==== Options (mail_params)
|
259
|
+
# MailFactory recognizes the following parameters:
|
260
|
+
# * :to
|
261
|
+
# * :from
|
262
|
+
# * :replyto
|
263
|
+
# * :subject
|
264
|
+
# * :body
|
265
|
+
# * :cc
|
266
|
+
#
|
267
|
+
# Other parameters passed in will be interpreted as email headers, with
|
268
|
+
# underscores converted to dashes.
|
269
|
+
def dispatch_and_deliver(method, mail_params)
|
270
|
+
@mailer = self.class._mailer_klass.new(mail_params)
|
271
|
+
@mail = @mailer.mail
|
272
|
+
@method = method
|
273
|
+
|
274
|
+
# dispatch and render use params[:action], so set it
|
275
|
+
self.action_name = method
|
276
|
+
|
277
|
+
body = _dispatch method
|
278
|
+
if !@mail.html.blank? || !@mail.text.blank?
|
279
|
+
@mailer.deliver!
|
280
|
+
Merb.logger.info "#{method} sent to #{@mail.to} about #{@mail.subject}"
|
281
|
+
else
|
282
|
+
Merb.logger.info "#{method} was not sent because nothing was rendered for it"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
# A convenience method that creates a blank copy of the MailController and
|
287
|
+
# runs dispatch_and_deliver on it.
|
288
|
+
#
|
289
|
+
# ==== Parameters
|
290
|
+
# method<~to_s>:: The method name to dispatch to.
|
291
|
+
# mail_params<Hash>:: Parameters to send to MailFactory.
|
292
|
+
# send_params<Hash>:: Configuration parameters for the MailController.
|
293
|
+
def self.dispatch_and_deliver(method, mail_params, send_params = {})
|
294
|
+
new(send_params).dispatch_and_deliver method, mail_params
|
295
|
+
end
|
296
|
+
|
297
|
+
protected
|
298
|
+
|
299
|
+
# ==== Returns
|
300
|
+
# Hash:: The route from base controller.
|
301
|
+
def route
|
302
|
+
@base_controller.route if @base_controller
|
303
|
+
end
|
304
|
+
|
305
|
+
private
|
306
|
+
# This method is here to overwrite the one in the general_controller mixin
|
307
|
+
# The method ensures that when a url is generated with a hash, it contains
|
308
|
+
# a controller.
|
309
|
+
#
|
310
|
+
# ==== Parameters
|
311
|
+
# opts<Hash>:: The options to get the controller from (see below).
|
312
|
+
#
|
313
|
+
# ==== Options (opts)
|
314
|
+
# :controller<Merb::Controller>:: The controller.
|
315
|
+
#
|
316
|
+
# ==== Returns
|
317
|
+
# Merb::Controller::
|
318
|
+
# The controller. If no controller was specified in opts, attempt to find
|
319
|
+
# it in the base controller params.
|
320
|
+
def get_controller_for_url_generation(opts)
|
321
|
+
controller = opts[:controller] || ( @base_controller.params[:controller] if @base_controller)
|
322
|
+
raise "No Controller Specified for url()" unless controller
|
323
|
+
controller
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
end
|
328
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
begin
|
2
|
+
require 'mailfactory'
|
3
|
+
require 'net/smtp'
|
4
|
+
rescue LoadError
|
5
|
+
Merb.logger.warn "You need to install the mailfactory gem to use Merb::Mailer"
|
6
|
+
end
|
7
|
+
|
8
|
+
class MailFactory
|
9
|
+
attr_reader :html, :text
|
10
|
+
end
|
11
|
+
|
12
|
+
module Merb
|
13
|
+
|
14
|
+
# You'll need a simple config like this in init.rb if you want
|
15
|
+
# to actually send mail:
|
16
|
+
#
|
17
|
+
# Merb::Mailer.config = {
|
18
|
+
# :host => 'smtp.yourserver.com',
|
19
|
+
# :port => '25',
|
20
|
+
# :user => 'user',
|
21
|
+
# :pass => 'pass',
|
22
|
+
# :auth => :plain # :plain, :login, :cram_md5, the default is no auth
|
23
|
+
# :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
24
|
+
# }
|
25
|
+
#
|
26
|
+
# or
|
27
|
+
#
|
28
|
+
# Merb::Mailer.config = {:sendmail_path => '/somewhere/odd'}
|
29
|
+
# Merb::Mailer.delivery_method = :sendmail
|
30
|
+
#
|
31
|
+
# You could send mail manually like this (but it's better to use
|
32
|
+
# a MailController instead).
|
33
|
+
#
|
34
|
+
# m = Merb::Mailer.new :to => 'foo@bar.com',
|
35
|
+
# :from => 'bar@foo.com',
|
36
|
+
# :subject => 'Welcome to whatever!',
|
37
|
+
# :body => partial(:sometemplate)
|
38
|
+
# m.deliver!
|
39
|
+
|
40
|
+
class Mailer
|
41
|
+
|
42
|
+
class_inheritable_accessor :config, :delivery_method, :deliveries
|
43
|
+
attr_accessor :mail
|
44
|
+
self.deliveries = []
|
45
|
+
|
46
|
+
# Sends the mail using sendmail.
|
47
|
+
def sendmail
|
48
|
+
sendmail = IO.popen("#{config[:sendmail_path]} #{@mail.to}", 'w+')
|
49
|
+
sendmail.puts @mail.to_s
|
50
|
+
sendmail.close
|
51
|
+
end
|
52
|
+
|
53
|
+
# Sends the mail using SMTP.
|
54
|
+
def net_smtp
|
55
|
+
Net::SMTP.start(config[:host], config[:port].to_i, config[:domain],
|
56
|
+
config[:user], config[:pass], config[:auth]) { |smtp|
|
57
|
+
smtp.send_message(@mail.to_s, @mail.from.first, @mail.to.to_s.split(/[,;]/))
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Tests mail sending by adding the mail to deliveries.
|
62
|
+
def test_send
|
63
|
+
deliveries << @mail
|
64
|
+
end
|
65
|
+
|
66
|
+
# Delivers the mail with the specified delivery method, defaulting to
|
67
|
+
# net_smtp.
|
68
|
+
def deliver!
|
69
|
+
send(delivery_method || :net_smtp)
|
70
|
+
end
|
71
|
+
|
72
|
+
# ==== Parameters
|
73
|
+
# file_or_files<File, Array[File]>:: File(s) to attach.
|
74
|
+
# filename<String>::
|
75
|
+
# type<~to_s>::
|
76
|
+
# The attachment MIME type. If left out, it will be determined from
|
77
|
+
# file_or_files.
|
78
|
+
# headers<String, Array>:: Additional attachment headers.
|
79
|
+
#
|
80
|
+
# ==== Raises
|
81
|
+
# ArgumentError::
|
82
|
+
# file_or_files was not a File or an Array of File instances.
|
83
|
+
def attach(file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil,
|
84
|
+
type = nil, headers = nil)
|
85
|
+
if file_or_files.is_a?(Array)
|
86
|
+
file_or_files.each {|k,v| @mail.add_attachment_as k, *v}
|
87
|
+
else
|
88
|
+
raise ArgumentError, "You did not pass in a file. Instead, you sent a #{file_or_files.class}" if !file_or_files.is_a?(File)
|
89
|
+
@mail.add_attachment_as(file_or_files, filename, type, headers)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# ==== Parameters
|
94
|
+
# o<Hash{~to_s => Object}>:: Configuration commands to send to MailFactory.
|
95
|
+
def initialize(o={})
|
96
|
+
self.config = {:sendmail_path => '/usr/sbin/sendmail'} if config.nil?
|
97
|
+
o[:rawhtml] = o.delete(:html)
|
98
|
+
m = MailFactory.new()
|
99
|
+
o.each { |k,v| m.send "#{k}=", v }
|
100
|
+
@mail = m
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Merb::Controller
|
2
|
+
# Sends mail via a MailController (a tutorial can be found in the
|
3
|
+
# MailController docs).
|
4
|
+
#
|
5
|
+
# ==== Parameters
|
6
|
+
# klass<Class>:: The mailer class.
|
7
|
+
# method<~to_s>:: The method to call on the mailer.
|
8
|
+
# mail_params<Hash>::
|
9
|
+
# Mailing parameters, e.g. :to and :cc. See
|
10
|
+
# Merb::MailController#dispatch_and_deliver for details.
|
11
|
+
# send_params<Hash>::
|
12
|
+
# Params to send to the mailer. Defaults to the params of the current
|
13
|
+
# controller.
|
14
|
+
#
|
15
|
+
# ==== Examples
|
16
|
+
# # Send an email via the FooMailer's bar method.
|
17
|
+
# send_mail FooMailer, :bar, :from => "foo@bar.com", :to => "baz@bat.com"
|
18
|
+
def send_mail(klass, method, mail_params, send_params = nil)
|
19
|
+
klass.new(send_params || params, self).dispatch_and_deliver(method, mail_params)
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb-mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yehuda Katz
|
8
|
+
autorequire: merb-mailer
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.2
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: mailfactory
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.2.3
|
32
|
+
version:
|
33
|
+
description: Merb plugin that provides mailer functionality to Merb
|
34
|
+
email: wycats@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README
|
41
|
+
- LICENSE
|
42
|
+
- TODO
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README
|
46
|
+
- Rakefile
|
47
|
+
- TODO
|
48
|
+
- lib/merb-mailer
|
49
|
+
- lib/merb-mailer/mail_controller.rb
|
50
|
+
- lib/merb-mailer/mailer.rb
|
51
|
+
- lib/merb-mailer/merb_controller.rb
|
52
|
+
- lib/merb-mailer.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://merb-plugins.rubyforge.org/merb-mailer/
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.0.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 2
|
78
|
+
summary: Merb plugin that provides mailer functionality to Merb
|
79
|
+
test_files: []
|
80
|
+
|