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 <[email protected]>'
            }.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 = "From: \#{options[:from_alias]} <\#{options[:from]}>\nTo: \#{addr}\nSubject: \#{options[:subject]}\n\n\#{options[:body]}\n"

    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 = "Hi,\n\nThe regression results are:\n\n\#{stats.summary_text}\n\n  END1\n\n  subject = \"[\#{Origen.app.namespace}] Regression - \"\n  if stats.clean_run?\n    subject += 'PASSED'\n  else\n    subject += 'FAILED'\n  end\n  send_email({ to: options[:to], subject: subject, body: msg }.merge(options))\nend\n"

#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 = "Hi,\n\n\#{header}\n\n    \#{version}    \#{selectors}\n\nRelease note:\n\n--------------------------------------------------------------------------------------\n\n\#{release_note}\n\n--------------------------------------------------------------------------------------\n    END1\n\n  if config.release_instructions\n    msg += <<-END2\n\n\#{config.release_instructions}\n\n--------------------------------------------------------------------------------------\n      END2\n  end\n\n  msg += <<-END3\n\nYou are receiving this because you are a member of the \#{config.name} Mailing List,\nor a member of the development team.\nEND3\n\n  if external?(type)\n    to = app_users + Origen.app.subscribers_prod + Origen.app.subscribers_dev\n    if config.release_email_subject\n      subject = \"[\#{Origen.app.namespace}] New Official Release: \#{config.release_email_subject}\"\n    else\n      subject = \"[\#{Origen.app.namespace}] New Official Release\"\n    end\n  else\n    to = admins + Origen.app.subscribers_dev\n    if config.release_email_subject\n      subject = \"[\#{Origen.app.namespace}] New Development Tag: \#{config.release_email_subject}\"\n    else\n      subject = \"[\#{Origen.app.namespace}] New Development Tag\"\n    end\n  end\n\n  begin\n    send_email({ to: to, subject: subject, body: msg }.merge(options))\n  rescue\n    warn \"Email could not be sent to \#{to}\"\n  end\nend\n"