Class: GmailMailer::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/gmail-mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to, subject = "", body = "") ⇒ Message

Returns a new instance of Message.



78
79
80
81
82
83
# File 'lib/gmail-mailer.rb', line 78

def initialize(to, subject="", body="")
  self.to=(to)
  @subject = subject
  @body = body
  @attachments = []
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



77
78
79
# File 'lib/gmail-mailer.rb', line 77

def attachments
  @attachments
end

#bodyObject

Returns the value of attribute body.



76
77
78
# File 'lib/gmail-mailer.rb', line 76

def body
  @body
end

#subjectObject

Returns the value of attribute subject.



76
77
78
# File 'lib/gmail-mailer.rb', line 76

def subject
  @subject
end

#toObject

Returns the value of attribute to.



77
78
79
# File 'lib/gmail-mailer.rb', line 77

def to
  @to
end

Instance Method Details

#add_attachment(filepath) ⇒ Object

Raises:

  • (ArgumentError)


85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gmail-mailer.rb', line 85

def add_attachment(filepath)
  raise ArgumentError, "You must specify a file to send" if filepath.nil? or filepath.empty?
  raise ArgumentError, "File #{filepath} does not exist" if !File.exist?(filepath)  
  raise ArgumentError, "#{filepath} file is a directory, this is not supported" if File.directory?(filepath)

  size = File.size(filepath)
  print "Adding attachment: #{filepath} " 
  printf("(%5.4f kb)",size.to_f/1024.0)
  puts
  raise ArgumentError, "There is a #{ATTACHMENTS_SIZE_LIMIT/1024/1024}mb limit on attachments}" if (get_attachments_size + size) > ATTACHMENTS_SIZE_LIMIT
  @attachments << filepath 
end

#get_attachments_sizeObject



105
106
107
108
109
110
111
# File 'lib/gmail-mailer.rb', line 105

def get_attachments_size
  attachments_size = 0
  @attachments.each do |attachment|
    attachments_size += File.size(attachment)
  end
  return attachments_size
end