Guest User

Untitled

a guest
Mar 7th, 2018
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. def gmail_connector(login,password,user_id,site_id)
  2. require 'tmail'
  3. username = login
  4. password = password
  5. Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
  6. Net::POP3.start('pop.gmail.com', 995, username, password) do |pop|
  7. if pop.mails.empty?
  8. puts 'No mail.'
  9. else
  10. pop.each_mail do |mail|
  11. email = TMail::Mail.parse(mail.pop)
  12. it = Item.create(:titre => "#{email.subject} [FROM : #{email.from}]", :texte => email.body)
  13. us = UserItem.create(:user_id => user_id, :site_id => site_id, :item_id => it.id)
  14. end
  15. end
  16. end
  17. end
Add Comment
Please, Sign In to add comment