Using Devise with PostageApp

Using Devise (>= 1.4.1) with PostageApp

Create a custom Postageapp mailer class as follows (you can also copy the default app/mailers/devise/mailer.rb file in the devise library and modify it accordingly):

class MyDeviseMailer < PostageApp::Mailer
  include Devise::Mailers::Helpers

  def confirmation_instructions(record)
    # PostageApp specific elements (example):
    postageapp_template 'my-signup-confirmation'
    postageapp_variables :email => record.email,
                         :link  => confirmation_url(:confirmation_token => record.confirmation_token)

    devise_mail(record, :confirmation_instructions)
  end

  def reset_password_instructions(record)
    # PostageApp specific elements (example):
    postageapp_template 'my-password-reset'
    postageapp_variables :name => record.name ||= record.email,
                         :link => password_url(:reset_password_token => record.reset_password_token)

    devise_mail(record, :reset_password_instructions)
  end

  def unlock_instructions(record)
    # PostageApp specific elements (example):
    postageapp_template 'my-unlock-instructions'
    postageapp_variables :name => record.name ||= record.email,
                         :link => unlock_url(:unlock_token => record.unlock_token)
    devise_mail(record, :unlock_instructions)
  end

protected
  # Ensures template subject is used instead of the default devise mailer subject.
  def headers_for(action)
    headers = super
    headers[:subject] = ‘’
    headers
  end
end

In the /config/initializers/devise.rb file, set the custom mailer to be:

config.mailer = "MyDeviseMailer"

UPDATE

Our good friend, Mark Foster, pointed out that emails sent through Devise without subject lines specified would send out the Devise defaults. As such, he has sent us an addition to his original Devise code (which we have updated above) that sends a blank subject line to the PostageApp API, which uses the templates you have specified in your backend.

Recent Discussions

19 Jul, 2017 06:30 PM
19 Jul, 2017 01:06 PM
09 Jul, 2017 09:09 PM
23 Jun, 2017 08:39 AM
22 Jun, 2017 07:33 PM