# Incoming email question

**URL:** <https://www.ruby-forum.com/t/incoming-email-question/92728>\
**Category:** Rails\
**Created:** [April 23, 2007, 3:20pm UTC](https://www.ruby-forum.com/t/incoming-email-question/92728 "2007-04-23T15:20:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 23, 2007, 3:20pm UTC](https://www.ruby-forum.com/t/incoming-email-question/92728/1 "2007-04-23T15:20:06Z")

</div>

I’m writing a model for receiving incoming email from a remote imap  
server.  
The problem is, our server isn’t going to be running all of the time,  
and so  
I’m just going to set it up to check the inbox on each request (there  
won’t  
be many requests, it’s not a public site). Our rails server is running  
Windows. This is what I have so far, pretty much copied from  
[http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer](http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer)

def recieve(email)  
emailer = Emailer.find\_by\_address(email.sender)  
emailer.messages.create(  
:incoming =\> true,  
:subject =\> email.subject,  
:body =\> email.body,  
:time =\> email  
)  
end

def send

# not done yet

end

def self.check\_mail  
imap = Net::IMAP.new(‘[imap.shef.accept.uk](http://imap.shef.accept.uk)’)  
imap.authenticate(‘LOGIN’,‘username’,‘password’)  
imap.select(‘INBOX’)  
imap.search([‘ALL’]).each do |message\_id|  
msg = imap.fetch(message\_id,‘RFC822’)[0].attr[‘RFC822’]  
MailReader.receive(msg)

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

end  
end

The problem is that because our server isn’t running all the time, I  
want to  
get the time the email was sent from the headers. This is very important  
as  
we have strict deadlines relating to replying to emails.

Any help would be much appreciated,  
-Nathan

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 23, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/incoming-email-question/92728/2 "2007-04-23T15:30:08Z")

</div>

oops, the line that say :time =\> email is in there because I presume  
it’s  
email.something, but I don’t know.  
-N
