# Simple IMAP client?

**URL:** <https://www.ruby-forum.com/t/simple-imap-client/147493>\
**Category:** Ruby\
**Created:** [September 2, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/simple-imap-client/147493 "2008-09-02T14:26:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 2, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/simple-imap-client/147493/1 "2008-09-02T14:26:15Z")

</div>

People,

I am thinking about writing a very simple IMAP client in Ruby (mostly  
for access from mobile phones) - anyone done anything like this?  
Suggestions?

Thanks,

## Phil.

Philip R.

GPO Box 3411  
Sydney NSW 2001  
Australia  
E-mail: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 2, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/simple-imap-client/147493/2 "2008-09-02T16:49:34Z")

</div>

The documentation for net/imap is pretty decent for figuring out what  
you want to do… Here is a piece of code from my original script that  
could get you started in the right direction.

require ‘net/imap’

imap = Net::IMAP.new(server)  
imap.login(user, pass)  
imap.examine(‘INBOX’)  
smtp = Net::SMTP.new(srvr, 25)  
imap.search([“UNSEEN”]).each do |message\_id|  
envelope = imap.fetch(message\_id, “ENVELOPE”)[0].attr[“ENVELOPE”]  
from = “#{envelope.from[0].mailbox}@#{envelope.from[0].host}”  
subj = envelope.subject  
end  
imap.logout

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 3, 2008, 6:34am UTC](https://www.ruby-forum.com/t/simple-imap-client/147493/3 "2008-09-03T06:34:02Z")

</div>

Anthony,

Thanks for that, I’ll give it a go!

Regards,

Phil.

Anthony P. wrote:

> imap.search([“UNSEEN”]).each do |message\_id|
> 
> > I am thinking about writing a very simple IMAP client in Ruby (mostly for  
> > Australia  
> > E-mail: removed\_email\_address@domain.invalid

–  
Philip R.

GPO Box 3411  
Sydney NSW 2001  
Australia  
E-mail: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 3, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/simple-imap-client/147493/4 "2008-09-03T19:12:17Z")

</div>

People,

I have made some progress with this and can look at mails (headers, body  
etc) but imap.store for changing flags has no affect and I don’t get any  
errors . .

Suggestions?

Thanks,

Phil.

Anthony P. wrote:

> imap.search([“UNSEEN”]).each do |message\_id|
> 
> > I am thinking about writing a very simple IMAP client in Ruby (mostly for  
> > Australia  
> > E-mail: removed\_email\_address@domain.invalid

–  
Philip R.

GPO Box 3411  
Sydney NSW 2001  
Australia  
E-mail: removed\_email\_address@domain.invalid
