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: [email protected]
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 [email protected] 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
[email protected] designates 11.11.111.11 as permitted sender)
[email protected]
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: [email protected]
Return-Path: [email protected]
Content-Type: multipart/alternative;
boundary=“d1512362-2905-4b45-8a7d-183ee6f27167”
X-Originating-IP: [147.243.216.4]
From: xxx xxx [email protected]
To: [email protected]
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_
MakeCoun=
t=
–d1512362-2905-4b45-8a7d-183ee6f27167
Content-Type: text/html; charset=“Windows-1252”
Content-Transfer-Encoding: quoted-printable
Make every e-mail and IM count. Jo= in the i=92m Initiative from Microsoft. =
–d1512362-2905-4b45-8a7d-183ee6f27167–
can some one pls help me~~~
sry for any problems or inconvinient
thx~~
cheers~~~