Class: Origen::Utility::Mailer

Inherits:
Object
  • Object
show all
Includes:
Origen::Users
Defined in:
lib/origen/utility/mailer.rb

Instance Method Summary collapse

Methods included from Origen::Users

#admins, #app_users, #current_user

Instance Method Details

#send_email(options = {}) ⇒ Object

Generic method to send an email, alternatively use one of the pre-defined mail types using the other methods.



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
40
41
42
43
# File 'lib/origen/utility/mailer.rb', line 9

def send_email(options = {})
  options = { server:     Origen.site_config.email_server,
              port:       Origen.site_config.email_port,
              from:       current_user.email,
              from_alias: current_user.name,
              subject:    'Hello',
              body:       'Hello from Origen!',
              to:         'Stephen McGinty <stephen.mcginty@freescale.com>'
            }.merge(options)

  # Force to an array
  to = options[:to].respond_to?('each') ? options[:to] : [options[:to]]

  # Convert any user objects to an email
  to = to.map { |obj| obj.respond_to?('email') ? obj.email : obj }

  to.uniq.each do |addr|
    msg = <<END_OF_MESSAGE
From: #{options[:from_alias]} <#{options[:from]}>
To: #{addr}
Subject: #{options[:subject]}

#{options[:body]}
END_OF_MESSAGE

    begin
      # Exceptions raised here will be caught by rescue clause
      Net::SMTP.start(options[:server], options[:port]) do |smtp|
        smtp.send_message msg, options[:from], addr
      end
    rescue
      warn "Email not able to be sent to address '#{addr}'"
    end
  end
end

#send_regression_complete_notice(stats = Origen.app.runner.stats, options = {}) ⇒ Object

Send a regression complete notice,



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/origen/utility/mailer.rb', line 108

def send_regression_complete_notice(stats = Origen.app.runner.stats, options = {})
  stats, options = Origen.app.runner.stats, stats if stats.is_a?(Hash)
  options = {
    to: current_user
  }.merge(options)

  msg = <<-END1
Hi,

The regression results are:

#{stats.summary_text}

  END1

  subject = "[#{Origen.app.namespace}] Regression - "
  if stats.clean_run?
    subject += 'PASSED'
  else
    subject += 'FAILED'
  end
  send_email({ to: options[:to], subject: subject, body: msg }.merge(options))
end

#send_release_notice(version, release_note, type, selectors, options = {}) ⇒ Object

Call to send a notice



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/origen/utility/mailer.rb', line 46

def send_release_notice(version, release_note, type, selectors, options = {})
  if external?(type)
    header = "A new version of #{config.name} is available:"
  else
    header = "A new development version of #{config.name} is available:"
  end

  msg = <<-END1
Hi,

#{header}

    #{version}    #{selectors}

Release note:

--------------------------------------------------------------------------------------

#{release_note}

--------------------------------------------------------------------------------------
    END1

  if config.release_instructions
    msg += <<-END2

#{config.release_instructions}

--------------------------------------------------------------------------------------
      END2
  end

  msg += <<-END3

You are receiving this because you are a member of the #{config.name} Mailing List,
or a member of the development team.
END3

  if external?(type)
    to = Origen.app.maillist_prod + Origen.app.maillist_dev
    if config.release_email_subject
      subject = "[#{Origen.app.namespace}] New Official Release: #{config.release_email_subject}"
    else
      subject = "[#{Origen.app.namespace}] New Official Release"
    end
  else
    to = Origen.app.maillist_dev
    if config.release_email_subject
      subject = "[#{Origen.app.namespace}] New Development Tag: #{config.release_email_subject}"
    else
      subject = "[#{Origen.app.namespace}] New Development Tag"
    end
  end

  begin
    send_email({ to: to, subject: subject, body: msg }.merge(options))
  rescue
    warn "Email could not be sent to #{to}"
  end
end