# Gmail imap

**URL:** <https://www.ruby-forum.com/t/gmail-imap/145575>\
**Category:** Ruby\
**Created:** [August 11, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/gmail-imap/145575 "2008-08-11T18:33:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [August 11, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/gmail-imap/145575/1 "2008-08-11T18:33:30Z")

</div>

how do i extract the message body using imap. i am hunting it and  
cannot seem to figure it out. probably i am not sure what the specific  
envelope attribute it should be. i tried envelope.body but it does not  
like it.

imap = Net::IMAP.new(‘[imap.gmail.com](http://imap.gmail.com)’,‘993’,true)  
imap.login(username, password)  
imap.select(‘INBOX’)

imap.search([“NOT”, “DELETED” ).each do |message\_id|  
envelope = imap.fetch(message\_id, “ENVELOPE”)[0].attr[“ENVELOPE”]  
puts “#{envelope.from[0].name}: \t#{envelope.subject}”

# imap.store(message\_id, “+FLAGS”, [:Deleted])

end

imap.logout()  
imap.disconnect()

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [August 12, 2008, 12:13am UTC](https://www.ruby-forum.com/t/gmail-imap/145575/2 "2008-08-12T00:13:26Z")

</div>

On Aug 11, 2008, at 09:27 AM, Junkone wrote:

> envelope = imap.fetch(message\_id, “ENVELOPE”)[0].attr[“ENVELOPE”]  
> puts “#{envelope.from[0].name}: \t#{envelope.subject}”
> 
> # imap.store(message\_id, “+FLAGS”, [:Deleted])
> 
> end
> 
> imap.logout()  
> imap.disconnect()

See RFC 3501 section 6.4.5. You probably want BODY[] judging from  
your example code.
