Last active
August 29, 2015 14:23
-
-
Save lienvdsteen/c17f0faa9a4ccade0ca9 to your computer and use it in GitHub Desktop.
Rails Mailing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add this to the file | |
config.action_mailer.delivery_method = :letter_opener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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