Class: Minimail::Mail
- Inherits:
-
Object
- Object
- Minimail::Mail
- Defined in:
- lib/minimail/mail.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#body(body = '') ⇒ Object
Returns the value of attribute body.
-
#recipients(recipients = nil) ⇒ Object
Returns the value of attribute recipients.
-
#subject(subject = nil) ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
- #deliver ⇒ Object
- #draft(&block) ⇒ Object
-
#initialize(params = {}) ⇒ Mail
constructor
A new instance of Mail.
- #mail_command ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Mail
Returns a new instance of Mail.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/minimail/mail.rb', line 5 def initialize(params = {}) mail_program? @recipients = params[:recipients] || [] @subject = params[:subject] || "" @body = params[:body] || "" = if encode_program? && params[:attachments] ( [params[:attachments]].flatten ) end end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments.
3 4 5 |
# File 'lib/minimail/mail.rb', line 3 def end |
#body(body = '') ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/minimail/mail.rb', line 3 def body @body end |
#recipients(recipients = nil) ⇒ Object
Returns the value of attribute recipients.
3 4 5 |
# File 'lib/minimail/mail.rb', line 3 def recipients @recipients end |
#subject(subject = nil) ⇒ Object
Returns the value of attribute subject.
3 4 5 |
# File 'lib/minimail/mail.rb', line 3 def subject @subject end |
Instance Method Details
#deliver ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/minimail/mail.rb', line 28 def deliver return "Invalid mail contents" unless valid? return "Invalid mail command" unless mail_command if IO.popen("(#{@attachments}) | #{mail_command} -s '#{@subject}' #{@recipients}", "w") do |io| io.write @body io.close_write io end else IO.popen("#{mail_command} -s '#{@subject}' #{@recipients}", "w") do |io| io.write @body io.close_write io end end end |
#draft(&block) ⇒ Object
55 56 57 |
# File 'lib/minimail/mail.rb', line 55 def draft(&block) instance_eval(&block) end |
#mail_command ⇒ Object
46 47 48 49 |
# File 'lib/minimail/mail.rb', line 46 def mail_command return '/usr/bin/mail' if command?('/usr/bin/mail') return '/bin/mail' if command?('/bin/mail') end |
#valid? ⇒ Boolean
51 52 53 |
# File 'lib/minimail/mail.rb', line 51 def valid? @recipients.empty? ? false : true end |