Skip to content

Mailers

cgebken edited this page Nov 6, 2020 · 3 revisions

Beyond Canvas comes with a mailer layout you can use for styling your emails. It is responsive and compatible with the most common email clients.

The mailer layout offers various partials that can be rendered in the email (see example below):

Partial Accepted variables
beyond_canvas/mailer/text &block
beyond_canvas/mailer/button locals[:url] (the URL of the button) and locals[:text] (the button text)

Example:

  1. Set layout 'beyond_canvas/mailer' on your ApplicationMailer:

    # app/mailers/application_mailer.rb
    
    class ApplicationMailer < ActionMailer::Base
      layout 'beyond_canvas/mailer'
    end
  2. Create your mailer and method as usual:

    # app/mailers/user_mailer.rb
    
    class UserMailer < ApplicationMailer
      def welcome_email
        # ...
      end
    end
  3. Make use of the Beyond Canvas mailer partials on your mailer view:

    <!-- app/views/user_mailer/welcome_email.html.erb -->
    
    <%= render 'beyond_canvas/mailer/text' do %>
      Welcome to our awesome app.
    <% end %>
    
    <%= render 'beyond_canvas/mailer/button', locals: { url: 'https://epages.com',
                                                        text: 'Visit our website' } %>