well, im tryin to read an email, which already is a txt file in my
folder, which name is ForActionMailer, but when i run the command it
shows this error
C:\rubydev\prac1\mail5>ruby script/runner
EventMailer.receive(STDIN.read) < ForA
ctionMailer.txt
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/runner.rb:47:
C:/rubydev
/prac1/mail5/app/models/event_mailer.rb:16:in `receive'': You have a nil
object w
hen you didn''t expect it! (NoMethodError)
The error occurred while evaluating nil.attachments from
C:/rubydev/prac1/ma
il5/app/models/event_mailer.rb:15:in `each''
from C:/rubydev/prac1/mail5/app/models/event_mailer.rb:15:in
`receive''
from
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer
/base.rb:373:in `receive''
from (eval):1
from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ev
al''
from
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/runner.rb:4
7
from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ge
m_original_require''
from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire''
from script/runner:3
require ''rubygems''
require ''action_mailer''
This is my Action mailer code:
class EventMailer < ActionMailer::Base
def receive(email)
page = Page.find_by_address(email.to.first)
page.emails.create(
:subject => email.subject,
:body => email.body
)
if email.has_attachments?
for attachment in email.attachments
page.attachments.create({
:file => attachment,
:description => email.subject
})
end
end
end
end
and i have this is my migrate folder
class CreateEmails < ActiveRecord::Migration
def self.up
create_table :emails do |t|
t.integer :page_id
t.string :subject
t.string :body
t.timestamps
end
end
def self.down
drop_table :emails
end
end
---------------------------------------------------
THIS is the content i wanna read. its the foractionmailer txt file
FFrom aaa Fri May 23 16:36:41 2008
Delivered-To: yyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Received: from gmail-pop.l.google.com [111.11.11.111]
by xxx.com with POP3 (fetchmail-6.3.8)
for <aaa@localhost> (single-drop); Fri, 23 May 2008 16:36:41 +0800
(MPST)
Received: by 11.111.111.11with SMTP id u16cs17333ebc;
Tue, 20 May 2008 23:42:23 -0700 (PDT)
Received: by 11.111.11.11 with SMTP id 2123p.1123123.1211231233039;
Tue, 20 May 2008 23:42:23 -0700 (PDT)
Received: from blu0-omc2-s19.blu0.hotmail.com
(blu0-omc2-s19.blu0.hotmail.com [11.111.11.11])
by mx.google.com with ESMTP id h4432 fh.30.2008.05.20.23.42.22;
Tue, 20 May 2008 23:42:23 -0700 (PDT)
Received-SPF: pass (google.com: domain of
xxx-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org designates
65.55.111.94 as permitted sender) client-ip=65.55.111.94;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of
xxx-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org designates 11.11.111.11 as permitted
sender)
smtp.mail=xxx-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org
Received: from Bewr46-W231 ([11.11.111.11]) by
blu0-omc2-s19.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959);
Tue, 20 May 2008 23:42:22 -0700
Message-ID: <B345D46-W234FERT365B41456ERT0-MsuGFMq8XAE@public.gmane.org>
Return-Path: xxx-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org
Content-Type: multipart/alternative;
boundary="_d1512362-2905-4b45-8a7d-183ee6f27167_"
X-Originating-IP: [147.243.216.4]
From: xxx xxx <xxx-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
To: <yyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: blablabla
Date: Wed, 21 May 2008 02:42:22 -0400
Importance: Normal
MIME-Version: 1.0
X-OriginalArrivalTime: 21 May 2008 06:42:22.0200 (UTC)
FILETIME=[D294DF80:01C8BB0D]
--_d1512362-2905-4b45-8a7d-183ee6f27167_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
asas
=20
_________________________________________________________________
Make every e-mail and IM count. Join the i=92m Initiative from
Microsoft.
http://im.live.com/Messenger/IM/Join/Default.aspx?source=3DEML_WL_
MakeCount
--_d1512362-2905-4b45-8a7d-183ee6f27167_
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class=3D''hmmessage''>
asas<BR><BR>
<DIV>
<BR>
<IMG alt=3D"Image by FlamingText.com"
src=3D"http://hmail.flamingtext.com/hmail/2003/05/16/flamingtext_com_1053058861_7286.jpg"
border=3D0><BR></DIV><br /><hr />Make every e-mail
and IM count. <a
href=3D''http://im.live.com/Messenger/IM/Join/Default.aspx?source=3DEML_WL_
MakeCount''
target=3D''_new''>Join the i=92m Initiative from
Microsoft.</a></body>
</html>
--_d1512362-2905-4b45-8a7d-183ee6f27167_--
can some one pls help me~~~
sry for any problems or inconvinient
thx~~
cheers~~~
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---