-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.rb
61 lines (50 loc) · 1.34 KB
/
email.rb
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
require "integrity"
require "sinatra/ditties/mailer"
module Integrity
class Notifier
class Email < Notifier::Base
attr_reader :to, :from
def self.to_haml
File.read(File.dirname(__FILE__) + "/config.haml")
end
def initialize(commit, config={})
@to = config.delete("to")
@from = config.delete("from")
super(commit, config)
configure_mailer
end
def deliver!
email.deliver!
end
def email
@email ||= Sinatra::Mailer::Email.new(
:to => to,
:from => from,
:text => body,
:subject => subject
)
end
def subject
"[Integrity] #{commit.project.name}: #{short_message}"
end
alias_method :body, :full_message
private
def configure_mailer
user = @config["user"] || ""
pass = @config["pass"] || ""
user = nil if user.empty?
pass = nil if pass.empty?
Sinatra::Mailer.delivery_method = "net_smtp"
Sinatra::Mailer.config = {
:host => @config["host"],
:port => @config["port"],
:user => user,
:pass => pass,
:auth => @config["auth"],
:domain => @config["domain"]
}
end
end
register Email
end
end