I am currently developing Mail application where the application can send emails and have inbox.
So, I follow this guide.
imap = Net::IMAP.new('mail.example.com')
imap.authenticate('LOGIN', 'joe_user', 'joes_password')
imap.examine('INBOX')
imap.search(["RECENT"]).each do |message_id|
envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
puts "#{envelope.from[0].name}: \t#{envelope.subject}"
end
But, I can't get the content of the email. I can't find any variables that keeps the content of the email. Could someone help me? Thank you.
Following is working for me with gmail as in explained here imap mail
require 'net/imap'
imap = Net::IMAP.new("imap.gmail.com", 993, usessl = true)
imap.login("username", "password")
imap.examine('INBOX')
imap.search(["ALL"]).each do |message_id|
env = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
raw_message = imap.fetch(message_id,'RFC822').first.attr['RFC822']
puts "#{env.from[0].name}: \t#{env.subject}"
puts "raw message: #{raw_message}"
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With