# Receiving emails?

**URL:** <https://www.ruby-forum.com/t/receiving-emails/173917>\
**Category:** Rails\
**Created:** [August 18, 2009, 9:31am UTC](https://www.ruby-forum.com/t/receiving-emails/173917 "2009-08-18T09:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siddarth\_Chandrasek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Siddarth\_Chandrasek](https://www.ruby-forum.com/u/Siddarth_Chandrasek)\
**Post date:** [August 18, 2009, 9:31am UTC](https://www.ruby-forum.com/t/receiving-emails/173917/1 "2009-08-18T09:31:17Z")

</div>

I’m trying to write a mailer daemon of sorts. Here, I’m trying to look  
through every email received in some inbox by searching through the  
message  
body for a certain keyword. If the keyword was mentioned, an appropriate  
response is sent.

The action mailer  
guide[http://guides.rubyonrails.org/action\_mailer\_basics.html#receiving-emails](http://guides.rubyonrails.org/action_mailer_basics.html#receiving-emails)is  
quite useful:

"1. Implement a receive method in our mailer.

1. Configure your email server to forward emails from the address(es)  
you  
would like your app to receive to /path/to/app/script/runner  
‘UserMailer.receive(STDIN.read)’."

But I’m not sure how to do the second part: the email I’m dealing with  
is a  
Gmail account. How does this work?

Thanks,

Sid

---

<div class="post-metadata">

**Author:** ![Siddarth\_Chandrasek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Siddarth\_Chandrasek](https://www.ruby-forum.com/u/Siddarth_Chandrasek)\
**Post date:** [August 18, 2009, 10:11am UTC](https://www.ruby-forum.com/t/receiving-emails/173917/2 "2009-08-18T10:11:42Z")

</div>

On Aug 17, 4:13 pm, Siddarth Chandrasekaran  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. Configure your email server to forward emails from the address(es) you  
> would like your app to receive to /path/to/app/script/runner  
> ‘UserMailer.receive(STDIN.read)’."
> 
> But I’m not sure how to do the second part: the email I’m dealing with is a  
> Gmail account. How does this work?
> 
> Thanks,
> 
> Sid

It doesn’t work… the guide is assuming that 1) you have control of  
the mail server and 2) the mail server and your app reside on the same  
machine (at least this is my understaning, please correct me if  
wrong). The easiest way I know of to do this is to write a daemon that  
periodically uses IMAP to search for messages of the given criteria.  
IMAP can be more than a bit tricky though, but definitely ask when you  
run into stumbling blocks. (I’ve yet to find an IMAP gem that I  
dislike little enough to actually use :\ but the source for sup is a  
good place to get an understanding of how Net::IMAP works)
