Class: Mail::Message

### Home Classes Methods

### In Files

- lib/padrino-mailer/ext.rb

### Parent

Object

### Methods

- ::caller_locations
- ::default_encoding
- ::logging=
- ::logging?
- ::reload_templates=
- ::reload_templates?
- ::templates
- ::views
- ::views=
- #add_resolved_part
- #content_type_with_symbol
- #defaults=
- #do_delivery_with_logging
- #html_part
- #initialize_with_app
- #locals
- #part
- #provides
- #settings
- #text_part
- #via
- #views

### Included Modules

- Sinatra::Templates
- Padrino::Rendering

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Mailer
- Padrino::Mailer::Base
- Padrino::Mailer::Helpers
- Padrino::Mailer::Helpers::ClassMethods
- Padrino::Mailer::Mime
- Mail
- Mail::Message

No matching classes.

# Mail::Message

### Attributes

template_cache[R]

### Public Class Methods

caller_locations() click to toggle source

Return the path of this file, only for compatibility with Sinatra rendering methods.

    # File lib/padrino-mailer/ext.rb, line 179
    def self.caller_locations
      [[File.dirname(__FILE__), 1]]
    end

default_encoding() click to toggle source

Return the default encoding.

    # File lib/padrino-mailer/ext.rb, line 186
    def self.default_encoding
      "utf-8"
    end

logging=(value) click to toggle source

    # File lib/padrino-mailer/ext.rb, line 205
    def self.logging=(value)
      @_logging = value
    end

logging?() click to toggle source

Check if we can log.

    # File lib/padrino-mailer/ext.rb, line 201
    def self.logging?
      @_logging
    end

reload_templates=(value) click to toggle source

Modify whether templates should be reloaded (for development).

    # File lib/padrino-mailer/ext.rb, line 165
    def self.reload_templates=(value)
      @_reload_templates = value
    end

reload_templates?() click to toggle source

Returns true if the templates will be reloaded; false otherwise.

    # File lib/padrino-mailer/ext.rb, line 172
    def self.reload_templates?
      @_reload_templates
    end

templates() click to toggle source

Returns the templates for this message.

    # File lib/padrino-mailer/ext.rb, line 144
    def self.templates
      @_templates ||= {}
    end

views() click to toggle source

Returns the template view path defined for this message.

    # File lib/padrino-mailer/ext.rb, line 158
    def self.views
      @_views
    end

views=(value) click to toggle source

Sets the message defined template path to the given view path.

    # File lib/padrino-mailer/ext.rb, line 151
    def self.views=(value)
      @_views = value
    end

### Public Instance Methods

add_resolved_part(attributes = {}, &block) click to toggle source

    # File lib/padrino-mailer/ext.rb, line 79
    def add_resolved_part(attributes = {}, &block)
      variable, value, content_type = attributes.values_at(:variable, :value, :content_type)
      if block_given? || value
        instance_variable_set "@#{variable}", self.part(:content_type => content_type,
                                                        :body => value,
                                                        :part_block => block)
        add_multipart_alternate_header unless self.send(variable).blank?
      else
        instance_variable_get("@#{variable}") || find_first_mime_type(content_type)
      end
    end

content_type_with_symbol(value=nil) click to toggle source

If the value is empty return a symbol that represent the content type so:

    "text/plain" => :plain

See Padrino::Mailer::Mime for more usage informations.

    # File lib/padrino-mailer/ext.rb, line 229
    def content_type_with_symbol(value=nil)
      value = Padrino::Mailer::Mime::MIME_TYPES.find { |k,v| v == value }[0] rescue value if value.is_a?(Symbol)
      mime = content_type_without_symbol(value)
      Padrino::Mailer::Mime.mime_type(mime)
    end

defaults=(attributes) click to toggle source

Modify the default attributes for this message (if not explicitly specified).

    # File lib/padrino-mailer/ext.rb, line 193
    def defaults=(attributes)
      @_defaults = attributes
      @_defaults.each_pair { |k, v| default(k.to_sym, v) } if @_defaults.is_a?(Hash)
    end

do_delivery_with_logging() click to toggle source

    # File lib/padrino-mailer/ext.rb, line 113
    def do_delivery_with_logging
      logger.debug "Sending email to: #{destinations.join(" ")}"
      encoded.to_lf.split("\n").each { |line| logger << ("  " + line) } if logger.debug?
      do_delivery_without_logging
    end

html_part(value = nil, &block) click to toggle source

Helper to add a HTML part to a multipart/alternative email. If this and text_part are both defined in a message, then it will be a multipart/alternative message and set itself that way.

@example

    html_part "Some <b>Html</b> text"
    html_part { render('multipart/basic.html') }

    # File lib/padrino-mailer/ext.rb, line 72
    def html_part(value = nil, &block)
      add_resolved_part(:variable     => :html_part,
                        :value        => value,
                        :content_type => 'text/html',
                        &block)
    end

initialize_with_app(*args, &block) click to toggle source

    # File lib/padrino-mailer/ext.rb, line 7
    def initialize_with_app(*args, &block)
      @template_cache = Tilt::Cache.new
      # Check if we have an app passed into initialize
      if args[0].respond_to?(:views) && args[0].respond_to?(:reload_templates?)
        app                       = args.shift
        settings.views            = File.join(app.views, 'mailers')
        settings.reload_templates = app.reload_templates?
      else
        settings.views = File.expand_path("./mailers")
        settings.reload_templates = true
      end

      initialize_template_settings!

      initialize_without_app(*args, &block)
    end

locals(value) click to toggle source

Sets the local variables available within the message template.

    # File lib/padrino-mailer/ext.rb, line 137
    def locals(value)
      @_locals = value
    end

part(params = {}, &block) click to toggle source

Allows you to add a part in block form to an existing mail message object.

@example

    mail = Mail.new do
      part :content_type => "multipart/alternative", :content_disposition => "inline" do |p|
        p.part :content_type => "text/plain", :body => "test text\nline #2"
        p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
      end
    end

    # File lib/padrino-mailer/ext.rb, line 102
    def part(params = {}, &block)
      part_block = params.delete(:part_block)
      new_part = Mail::Part.new(params)
      new_part.settings.views = settings.views
      new_part.settings.reload_templates = settings.reload_templates?
      new_part.instance_eval(&part_block) if part_block
      yield new_part if block_given?
      add_part(new_part)
      new_part
    end

provides(*formats) click to toggle source

Setup like in Sinatra/Padrino apps content_type and template lookup.

@example

    # This add an email plain part if a template called bar.plain.* is found
    # and a HTML part if a template called bar.html.* is found
    email do
      from     'from@email.com'
      to       'to@email.com'
      subject  'Welcome here'
      provides :plain, :html
      render   "foo/bar"
    end

    # File lib/padrino-mailer/ext.rb, line 39
    def provides(*formats)
      if formats.empty?
        @_provides ||= []
      else
        @_provides = formats.flatten.compact
      end
    end

settings() click to toggle source

Sinatra and Padrino compatibility.

    # File lib/padrino-mailer/ext.rb, line 123
    def settings
      self.class
    end

text_part(value = nil, &block) click to toggle source

Helper to add a text part to a multipart/alternative email. If this and html_part are both defined in a message, then it will be a multipart/alternative message and set itself that way.

@example

    text_part "Some text"
    text_part { render('multipart/basic.text') }

    # File lib/padrino-mailer/ext.rb, line 56
    def text_part(value = nil, &block)
      add_resolved_part(:variable     => :text_part,
                        :value        => value,
                        :content_type => 'text/plain',
                        &block)
    end

via(method = nil, settings = {}) click to toggle source

Shortcut for delivery_method with smarter SMTP overwrites.

    # File lib/padrino-mailer/ext.rb, line 212
    def via(method = nil, settings = {})
      if method.nil?
        delivery_method
      elsif method.to_sym != :smtp
        delivery_method(method, settings)
      elsif method.to_sym == :smtp && (settings.any? || delivery_method.class.to_s !~ /smtp/)
        delivery_method(method, settings)
      end
    end

views(value) click to toggle source

Sets the message defined template path to the given view path.

    # File lib/padrino-mailer/ext.rb, line 130
    def views(value)
      settings.views = value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.