Class: Subtrigger::Email
- Inherits:
-
Object
- Object
- Subtrigger::Email
- Defined in:
- lib/subtrigger/email.rb
Overview
E-mail notifications
Sometimes you want to send notification e-mails after the hook has fired to inform developers or yourself of some event. This class is a simple wrapper around the standard sendmail
program.
Usage example
Email.new(:to => '[email protected]',
:from => '[email protected]',
:subject => 'Fired',
:body => 'Your post-commit hook has just fired').send
If sendmail
can not be found on your system an exception will be raised.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#development ⇒ Object
Returns the value of attribute development.
-
#from ⇒ Object
Returns the value of attribute from.
-
#sendmail ⇒ Object
readonly
Returns the value of attribute sendmail.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Email
constructor
Sets up a new message and tries to find
sendmail
on your system. -
#send ⇒ Object
Tries to use
sendmail
to send the message.
Constructor Details
#initialize(options = {}) ⇒ Email
Sets up a new message and tries to find sendmail
on your system.
21 22 23 24 25 26 27 28 29 |
# File 'lib/subtrigger/email.rb', line 21 def initialize( = {}) @to = [:to] @from = [:from] @subject = [:subject] @body = [:body] @development = [:development] || false @sendmail = Subtrigger.sendmail || `which sendmail`.strip raise 'Could not find sendmail; aborting.' if @sendmail.nil? end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
17 18 19 |
# File 'lib/subtrigger/email.rb', line 17 def body @body end |
#development ⇒ Object
Returns the value of attribute development.
17 18 19 |
# File 'lib/subtrigger/email.rb', line 17 def development @development end |
#from ⇒ Object
Returns the value of attribute from.
17 18 19 |
# File 'lib/subtrigger/email.rb', line 17 def from @from end |
#sendmail ⇒ Object (readonly)
Returns the value of attribute sendmail.
18 19 20 |
# File 'lib/subtrigger/email.rb', line 18 def sendmail @sendmail end |
#subject ⇒ Object
Returns the value of attribute subject.
17 18 19 |
# File 'lib/subtrigger/email.rb', line 17 def subject @subject end |
#to ⇒ Object
Returns the value of attribute to.
17 18 19 |
# File 'lib/subtrigger/email.rb', line 17 def to @to end |
Instance Method Details
#send ⇒ Object
Tries to use sendmail
to send the message. The message sent is returned for inspecting purposes.
33 34 35 36 37 38 39 40 41 |
# File 'lib/subtrigger/email.rb', line 33 def send = header + "\n" + body unless development fd = open("|#{sendmail} #{to}", "w") fd.print() fd.close end end |