mailer.rb
2.23 KB
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
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
# Haml doesn't load routes automatically when called via a rake task.
# This is only necessary when sending test emails (i.e. from rake hoptoad:test)
require Rails.root.join('config/routes.rb')
class Mailer < ActionMailer::Base
helper ApplicationHelper
default :from => Errbit::Config.email_from,
'X-Errbit-Host' => Errbit::Config.host,
'X-Mailer' => 'Errbit',
'X-Auto-Response-Suppress' => 'OOF, AutoReply',
'Precedence' => 'bulk',
'Auto-Submitted' => 'auto-generated'
def err_notification(error_report)
@notice = NoticeDecorator.new error_report.notice
@app = AppDecorator.new error_report.app
count = error_report.problem.notices_count
count = count > 1 ? "(#{count}) " : ""
errbit_headers 'App' => @app.name,
'Environment' => @notice.environment_name,
'Error-Id' => @notice.err_id
mail :to => @app.notification_recipients,
:subject => "#{count}[#{@app.name}][#{@notice.environment_name}] #{@notice.message.truncate(50)}"
end
def deploy_notification(deploy)
@deploy = deploy
@app = AppDecorator.new deploy.app
errbit_headers 'App' => @app.name,
'Environment' => @deploy.environment,
'Deploy-Revision' => @deploy.revision,
'Deploy-User' => @deploy.username
mail :to => @app.notification_recipients,
:subject => "[#{@app.name}] Deployed to #{@deploy.environment} by #{@deploy.username}"
end
def comment_notification(comment)
@comment = comment
@user = comment.user
@problem = ProblemDecorator.new comment.err
@notice = @problem.notices.first
@app = @problem.app
recipients = @comment.notification_recipients
errbit_headers 'App' => @app.name,
'Environment' => @notice.environment_name,
'Problem-Id' => @problem.id,
'Comment-Author' => @user.name
mail :to => recipients,
:subject => "#{@user.name} commented on [#{@app.name}][#{@notice.environment_name}] #{@notice.message.truncate(50)}"
end
private def errbit_headers(header)
header.each { |key,value| headers["X-Errbit-#{key}"] = value.to_s }
end
end