Tutorial by Examples

This example uses four different files: The User model The User mailer The html template for the email The plain-text template for the email In this case, the user model calls the approved method in the mailer and passes the post that has been approved (the approved method in the model may ...
To generate a new mailer, enter the following command rails generate mailer PostMailer This will generate a blank template file in app/mailers/post_mailer.rb named PostMailer class PostMailer < ApplicationMailer end Two layout files will also be generated for the email view, one for the...
ActionMailer also allows attaching files. attachments['filename.jpg'] = File.read('/path/to/filename.jpg') By default, attachments will be encoded with Base64. To change this, you can add a hash to the attachments method. attachments['filename.jpg'] = { mime_type: 'application/gzip', enco...
ActionMailer supports three callbacks before_action after_action around_action Provide these in your Mailer class class UserMailer < ApplicationMailer after_action :set_delivery_options, :prevent_delivery_to_guests, :set_business_headers Then create these methods under the private ...
Create the Newsletter model: rails g model Newsletter name:string email:string subl app/models/newsletter.rb validates :name, presence: true validates :email, presence: true Create the Newsletter controller: rails g controller Newsletters create class NewslettersCont...
Action Mailer provides hooks into the interceptor methods. These allow you to register classes that are called during the mail delivery life cycle. An interceptor class must implement the :delivering_email(message) method which will be called before the email is sent, allowing you to make modificat...

Page 1 of 1