class GmailRubyUtilities

Public Class Methods

getCountOfEmailsWithRecipientId(username,password,recipient) click to toggle source
# File lib/gmailRubyUtilities.rb, line 37
def self.getCountOfEmailsWithRecipientId(username,password,recipient)
  gmail = Gmail.connect(username, password)
  puts gmail.inbox.count(:to => recipient)
end
markAllEmailsAsRead(username,password,sender) click to toggle source
# File lib/gmailRubyUtilities.rb, line 20
def self.markAllEmailsAsRead(username,password,sender)
  gmail = Gmail.connect(username, password)
   gmail.inbox.find(:from =>sender,:unread=> true ).each do |email|
     email.read!
   end
end
readHtmlPartOfLatestMailFromGmail(username,password,sender) click to toggle source
# File lib/gmailRubyUtilities.rb, line 9
def self.readHtmlPartOfLatestMailFromGmail(username,password,sender)
  gmail = Gmail.connect(username, password)
  mail=gmail.inbox.find(:from => sender,:unread=> true).last
  htmlPart=mail.html_part.decoded
end
readLinkFromLatestMailFromGmail(username,password,sender) click to toggle source
# File lib/gmailRubyUtilities.rb, line 4
def self.readLinkFromLatestMailFromGmail(username,password,sender)
  gmail = Gmail.connect(username, password)
  mail=gmail.inbox.find(:from => sender,:unread=> true).last
  linkInTheEmail=mail.html_part.decoded.scan(/<a.+?href="(.+?)".+?/)[0]
end
readTextPartOfLatestMailFromGmail(username,password,sender) click to toggle source
# File lib/gmailRubyUtilities.rb, line 14
def self.readTextPartOfLatestMailFromGmail(username,password,sender)
  gmail = Gmail.connect(username, password)
  mail=gmail.inbox.find(:from => sender,:unread=> true).last
  textPart=mail.text_part.decoded
end
sendEmail(username,password,emailId,subject,body) click to toggle source
# File lib/gmailRubyUtilities.rb, line 27
def self.sendEmail(username,password,emailId,subject,body)
  gmail = Gmail.connect(username, password)
  email = gmail.compose do
    to emailId
    subject subject
    body body
  end
  email.deliver!
end