1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
class UserMailer < ActionMailer::Base
default :from => "admin@example.com",
:sent_on => Time.now.to_s
def signup(email, name)
@name = name
mail :to => email,
:subject => "Account confirmation"
end
def newsletter(email, name)
@name = name
mail :to => email,
:subject => "Newsletter sent"
end
def email_with_attachment(email, name)
@name = name
add_attachment 'image.png'
add_attachment 'document.pdf'
mail :to => email,
:subject => "Attachments test"
end
private
def add_attachment(attachment_name)
attachment_path = "#{Rails.root}/attachments/#{attachment_name}"
File.open(attachment_path) do |file|
filename = File.basename(file.path)
attachments[filename] = {:content_type => File.mime_type?(file), :content => file.read}
end
end
end
|