File: user_mailer.rb

package info (click to toggle)
ruby-email-spec 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 980 kB
  • sloc: ruby: 2,420; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 859 bytes parent folder | download
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