Created
June 21, 2014 10:15
-
-
Save gunesmes/09d04090e5671c11a20a to your computer and use it in GitHub Desktop.
With this module, you can create test e-mail address and you can check if you get a related email. You can use this for Google account.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/imap' | |
class TestData | |
def initialize() | |
@emailBase = "username" | |
@emailSup = "gmail.com" | |
@password = "password" | |
@emails = "" | |
end | |
def create_email(number_of_email=1) | |
# read the text file as a list of lines | |
# find the last line, and insert new line | |
data = open('numberRun.txt', "r") | |
lineList = data.readlines() | |
data.close() | |
now = Time.new | |
#first time running, empty list | |
if lineList.length == 0 | |
lastLineList = '0' + ',' + @emailBase + ',' + now.strftime("%Y-%m-%d_%H:%M") + ',' + 'False' | |
else | |
lastLineList = lineList[lineList.length - 1] | |
end | |
list = lastLineList.split(',') | |
lastUsedNumber = list[0].gsub("[", "").to_i | |
lastUsedEmail = list[1].to_s | |
date = list[2].to_s | |
isRegistered = list[3].gsub("]", "").to_s | |
data = open('./numberRun.txt', "a") | |
for i in 1..number_of_email | |
newEmail = @emailBase + '+' + (lastUsedNumber + i).to_s + '@' + @emailSup | |
@emails << newEmail << ", " | |
newEmailFull = lastUsedNumber + i, newEmail, now.strftime("%Y-%m-%d_%H:%M"), "YES" | |
data.write(newEmailFull) | |
data.write("\n") | |
end | |
data.close() | |
@emails = @emails[0..-3] | |
puts @emails | |
return @emails | |
end | |
def get_email() | |
imap = Net::IMAP.new('imap.gmail.com',993,true) | |
imap.login((@emailBase + '@' + @emailSup), @password) | |
imap.select('INBOX') | |
mailIds = imap.search([1]) | |
mailIds.each do |id| | |
msg = imap.fetch(id,'RFC822')[0].attr['RFC822'] | |
return msg | |
end | |
imap.logout() | |
imap.disconnect() | |
end | |
def check_email_content(search_content) | |
content = get_email() | |
result = false | |
if content.length == 0 | |
puts "There is no e-mail" | |
result = false | |
elsif content.include?(search_content) | |
puts "e-mail has content: #{search_content}" | |
result = true | |
else | |
puts "e-mail has no content: #{search_content}" | |
result = false | |
end | |
return result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment