Lux::Mailer - send mails

Example

sugessted usage

Mailer.deliver(:email_login, 'foo@bar.baz')
Mailer.render(:email_login, 'foo@bar.baz')

natively works like

Mailer.prepare(:email_login, 'foo@bar.baz').deliver
Mailer.prepare(:email_login, 'foo@bar.baz').body

Rails mode via method missing is suported

Mailer.email_login('foo@bar.baz').deliver
Mailer.email_login('foo@bar.baz').body

Example code

class Mailer < Lux::Mailer
  helper :mailer

  # before mail is sent
  after do
    mail.from = "#{App.name} <no-reply@#{Lux.config.host}>"
  end

  # raw define mail
  def raw to:, subject:, body:
    mail.subject = subject
    mail.to      = to
    mail.body    = body.as_html
  end

  # send mail as
  #   Mailer.lost_password('foo@bar.baz').deliver
  #
  # renders tamplate and layout
  #   ./app/views/mailer/lost_password.haml
  #   ./app/views/mailer/layout.haml
  def lost_password email
    mail.subject = "#{App.name} – potvrda registracije"
    mail.to      = email

    @link    = "#{App.http_host}/profile/password?user_hash=#{Crypt.encrypt(email)}"
  end
end