Skip to content

Instantly share code, notes, and snippets.

@lienvdsteen
Last active August 29, 2015 14:23
Show Gist options
  • Save lienvdsteen/c17f0faa9a4ccade0ca9 to your computer and use it in GitHub Desktop.
Save lienvdsteen/c17f0faa9a4ccade0ca9 to your computer and use it in GitHub Desktop.
Rails Mailing
# add this to the file
config.action_mailer.delivery_method = :letter_opener
Rails.application.configure do
ActionMailer::Base.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => ENV['MANDRILL_USERNAME'],
:password => ENV['MANDRILL_APIKEY'],
:domain => 'heroku.com',
:authentication => :plain
}
ActionMailer::Base.delivery_method = :smtp
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
after_create :send_welcome_email
private
def send_welcome_email
UserMailer.welcome(self).deliver
end
end
class UserMailer < ApplicationMailer
default from: 'user@domain.com'
def welcome(user)
# make the user available for the view (it needs to be an instance variable for this)
@user = user
# this will render the view in app/views/user_mailer
mail(to: @user.email, subject: 'Welcome to this demo')
end
end
Hi <%= @user.name %>,
Today we'll talk about SMTP and Mandrill!
See ya!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment