-
-
Save fronx/281436 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Notifier < ActionMailer::Base | |
delivers_from '[email protected]' | |
def welcome(user) | |
@user = user # available to the view | |
mail(:subject => 'Welcome!', :to => user.email_address) | |
# auto renders both welcome.text.erb and welcome.html.erb | |
end | |
def goodbye(user) | |
headers["Reply-To"] = '[email protected]' | |
mail(:subject => 'Goodbye', :to => user.email_address) do |format| | |
format.html { render "shared_template "} | |
format.text # goodbye.text.erb | |
end | |
end | |
def surprise(user, gift) | |
attachments[gift.name] = File.read(gift.path) | |
mail(:subject => 'Surprise!', :to => user.email_address) do |format| | |
format.html(:charset => "ascii") # goodbye.html.erb | |
format.text(:transfer_encoding => "base64") # goodbye.text.erb | |
end | |
end | |
def special_surprise(user, gift) | |
attachments[gift.name] = { :content_type => "application/x-gzip", :content => File.read(gift.path) } | |
mail(:to => '[email protected]') # subject not required | |
end | |
end | |
Notifier.new.welcome(user) # => returns a Mail object | |
Notifier.new.welcome(user).deliver # => sends the Mail object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment