class GmailMailer::Message

Attributes

attachments[R]
body[RW]
subject[RW]
to[R]

Public Class Methods

new(to, subject="", body="") click to toggle source
# File lib/gmail-mailer.rb, line 78
def initialize(to, subject="", body="")
  self.to=(to)
  @subject = subject
  @body = body
  @attachments = []
end

Public Instance Methods

add_attachment(filepath) click to toggle source
# 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_size() click to toggle source
# 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
to=(to) click to toggle source
# File lib/gmail-mailer.rb, line 98
def to=(to) 
  raise ArgumentError, "You must specify an email address to send the message to!" if(to.nil? or to.empty?)
  raise ArgumentError, "You cannot send a message to more than #{RECIPIENT_LIMIT} recipients" if to.is_a?Array and to.count > RECIPIENT_LIMIT
  @to = to.join(";") if to.is_a?Array 
  @to = to if to.is_a?String 
end