Module: ActionMailer::PartContainer

Included in:
Base, Part
Defined in:
lib/action_mailer/part_container.rb

Overview

Accessors and helpers that ActionMailer::Base and ActionMailer::Part have in common. Using these helpers you can easily add subparts or attachments to your message:

def my_mail_message(...)
  ...
  part "text/plain" do |p|
    p.body "hello, world"
    p.transfer_encoding "base64"
  end

  attachment "image/jpg" do |a|
    a.body = File.read("hello.jpg")
    a.filename = "hello.jpg"
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partsObject (readonly)

The list of subparts of this container



20
21
22
# File 'lib/action_mailer/part_container.rb', line 20

def parts
  @parts
end

Instance Method Details

#attachment(params, &block) ⇒ Object

Add an attachment to a multipart message. This is simply a part with the content-disposition set to “attachment”.



34
35
36
37
38
39
# File 'lib/action_mailer/part_container.rb', line 34

def attachment(params, &block)
  params = { :content_type => params } if String === params
  params = { :disposition => "attachment",
             :transfer_encoding => "base64" }.merge(params)
  part(params, &block)
end

#part(params) {|part| ... } ⇒ Object

Add a part to a multipart message, with the given content-type. The part itself is yielded to the block so that other properties (charset, body, headers, etc.) can be set on it.

Yields:



25
26
27
28
29
30
# File 'lib/action_mailer/part_container.rb', line 25

def part(params)
  params = {:content_type => params} if String === params
  part = Part.new(params)
  yield part if block_given?
  @parts << part
end