Class: Origen::Utility::Mailer
- Includes:
- Origen::Users
- Defined in:
- lib/origen/utility/mailer.rb
Instance Method Summary collapse
-
#send_email(options = {}) ⇒ Object
Generic method to send an email, alternatively use one of the pre-defined mail types using the other methods.
-
#send_regression_complete_notice(stats = Origen.app.runner.stats, options = {}) ⇒ Object
Send a regression complete notice,.
-
#send_release_notice(version, release_note, type, selectors, options = {}) ⇒ Object
Call to send a notice.
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 44 45 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 |
# File 'lib/origen/utility/mailer.rb', line 9 def send_email( = {}) = { 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: current_user.email, authentication: (Origen.site_config.email_authentication || :none).to_sym, domain: (Origen.site_config.email_domain || ''), auth_user: (Origen.site_config.email_auth_user || current_user.email), auth_password: (Origen.site_config.email_auth_password || current_user.password) }.merge() # Force to an array to = [:to].respond_to?('each') ? [:to] : [[: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: #{[:from_alias]} <#{[:from]}> To: #{addr} Subject: #{[:subject]} #{[:body]} END_OF_MESSAGE begin Origen.log.debug('Origen::Utility::Mailer Setup:') # Must not save a user's password to the Origen log file! So build a shadow copy of the # options hash and display that content in the log file with the auth_password removed. = .delete(:auth_password) .each { |k, v| Origen.log.debug(" #{k}: #{v}") } # Net::SMTP.start(options[:server], options[:port]) do |smtp| # smtp.send_message msg, options[:from], addr # end # Exceptions raised here will be caught by rescue clause smtp = Net::SMTP.new([:server], [:port]) smtp.enable_starttls if [:authentication] != :none opts = if [:authentication] == :none # Trying to add username and password if there's no authentication will actually be rejected by # the server. [[:domain]] else [[:domain], [:auth_user], [:auth_password], [:authentication]] end smtp.start(*opts) do |m| m.(msg, [:from], addr) end # Exceptions raised here will be caught by rescue clause # smtp = Net::SMTP.new(options[:server], options[:port]) # smtp.enable_starttls # smtp.start (options[:domain], options[:auth_user], options[:auth_password], options[:authentication]) 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,
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/origen/utility/mailer.rb', line 142 def send_regression_complete_notice(stats = Origen.app.runner.stats, = {}) stats, = Origen.app.runner.stats, stats if stats.is_a?(Hash) = { to: current_user }.merge() 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: [:to], subject: subject, body: msg }.merge()) end |
#send_release_notice(version, release_note, type, selectors, options = {}) ⇒ Object
Call to send a notice
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/origen/utility/mailer.rb', line 80 def send_release_notice(version, release_note, type, selectors, = {}) 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()) rescue warn "Email could not be sent to #{to}" end end |