· 8 years ago · Jan 21, 2018, 02:02 PM
1def get_mail
2 accounts = [
3 {"number" => 0, "email" => "###@gmail.com", "password" => "###"},
4 {"number" => 1, "email" => "###@gmail.com", "password" => "###"}
5 ]
6
7 accounts.each do |account|
8 Mail.defaults do
9 retriever_method :pop3, { :address => "pop.gmail.com",
10 :port => 995,
11 :user_name => account["email"],
12 :password => account["password"],
13 :enable_ssl => true }
14 end
15 emails = Mail.all
16 emails.each do |email|
17 from = mail.sender.address #=> 'mikel@test.lindsaar.net'
18 to = mail.to #=> 'bob@test.lindsaar.net'
19 subject = mail.subject #=> "This is the subject"
20 date = mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
21 body = mail.body.decoded #=> 'This is the body of the email...
22
23 #Save the email
24 record = Record.new(:name => to, :description => body)
25 record.save
26 end # end emails for loop
27 end # end addresses for loop
28 end