Class: TemplateMailer::MailMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/template_mailer/mail_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MailMessage

Hash…

* :html - The HTML content for the email message. Both this and
  text can be specified but at least one of them should be.
* :text - The textual content for the email message. Both this
  and :html can be specified but at least one should be.
* :server - When SMTP is the preferred email mecahnism (see the
  :via option) then this value should be a Hash of the parameters
  that will be used to talk to the SMTP server.
* :via - The email mechanism to use to dispatch email messages.
  options are :sendmail (the default) or :smtp. If :smtp is
  specified then the :server option should also be given a
  value.


19
20
21
22
23
24
# File 'lib/template_mailer/mail_message.rb', line 19

def initialize(options={})
  @html   = options[:html]
  @text   = options.fetch(:text, options[:txt])
   @server = options[:server]
   @via    = options.fetch(:via, :sendmail)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



25
26
27
# File 'lib/template_mailer/mail_message.rb', line 25

def html
  @html
end

#textObject (readonly)

Returns the value of attribute text.



25
26
27
# File 'lib/template_mailer/mail_message.rb', line 25

def text
  @text
end

Instance Method Details

#send(options = {}) ⇒ Object Also known as: dispatch

This method attempts to send the contents of a mail message to a specified set of recipients.

Parameters

options

A Hash of the options to be used when sending the email. Recognised keys in this Hash are :subject (a String containing the email title), :recipients (either a String or Array list of email addresses that the message should be sent to) and :from (the email address that will be set as the message source).



37
38
39
40
41
42
# File 'lib/template_mailer/mail_message.rb', line 37

def send(options={})
  if !options.include?(:recipients) || [nil, "", []].include?(options[:recipients])
    raise TemplateMailerError, "No recipients specified for email."
  end
  Pony.mail(send_settings(options))
end