Class: GmailRubyUtilities

Inherits:
Object
  • Object
show all
Defined in:
lib/gmailRubyUtilities.rb

Class Method Summary collapse

Class Method Details

.getTestLinkByRecipientEmailId(username, password, sender, recipient) ⇒ Object



39
40
41
42
43
44
# File 'lib/gmailRubyUtilities.rb', line 39

def self.getTestLinkByRecipientEmailId(username,password,sender,recipient)
  gmail = Gmail.connect(username, password)
  mail=gmail.inbox.find(:from => sender,:unread=> true,:to =>recipient).last
  linkInTheEmail=mail.html_part.decoded.scan(/<a.+?href="(.+?)".+?/)[0]
  puts linkInTheEmail
end

.markAllEmailsAsRead(username, password, sender) ⇒ Object



23
24
25
26
27
28
# File 'lib/gmailRubyUtilities.rb', line 23

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) ⇒ Object



10
11
12
13
14
15
# File 'lib/gmailRubyUtilities.rb', line 10

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
  puts htmlPart
end

.readLinkFromLatestMailFromGmail(username, password, sender) ⇒ Object



4
5
6
7
8
9
# 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]
  puts linkInTheEmail
end

.readTextPartOfLatestMailFromGmail(username, password, sender) ⇒ Object



16
17
18
19
20
21
# File 'lib/gmailRubyUtilities.rb', line 16

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
  puts textPart
end

.sendEmail(username, password, emailId, subject, body) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/gmailRubyUtilities.rb', line 30

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