Categories
ruby on rails

Customizing Mailboxer mailer views

To copy the mailboxer mailer views to your rails app run

rails g mailboxer:views

This will generate two folders, message_mailer and notification_mailer with html & text views for messages, notification and message replies respectively.

Next create a modify the initializer of mailboxer to include the following config

Mailboxer.setup do |config|
  #Enables or disables email sending for Notifications and Messages
  config.uses_emails = true
  #Configures the default `from` address for the email sent for Messages and Notifications of Mailboxer
  config.default_from = "admin@yoursite.com"
end

Add the following method to your messageable model

  #Returning the email address of the model if an email should be sent for this object (Message or Notification).
  #If no mail has to be sent, return nil.
  def mailboxer_email(object)
  #Check if an email should be sent for that object
  #if true
    return "define_email@on_your.model"
  #if false
  #return nil
  end

To change the title of you mail messages

open config/locales/en.yml and you will see the following line belonging to each mail you can the below line to suit to your needs

en:
  mailboxer:
    message_mailer:
      subject_new: "Mailboxer new message: %{subject}"
      subject_reply: "Mailboxer new reply: %{subject}"
    notification_mailer:
      subject: "Mailboxer new notification: %{subject}"