if email.has_attachments?
for attachment in email.attachments
page.attachments.create({
:file => attachment, :description => email.subject
})
end
end
end
Which part isn’t working? if Page. find_by_address is returning nil,
have you compared what’s in the database with what’s in the email
(bearing in the mind that the email will probably have something like
“Fred blogs [email protected]” whereas your database might only have [email protected]
.
receive is a class method in ActionMailer::Base that processes
incoming mail. What you usually do is pipe contents of the email, as a
string, from your mailing process to the receive method which
automatically converts it to a Tmail object.
This is the example for Rails Way (modified slightly to match your
class name) to listen for incoming mail:
if email.has_attachments?
for attachment in email.attachments
page.attachments.create({
:file => attachment, :description => email.subject
})
end
So i change the code to
if email.has_attachments?
email.attachments.each do |attachment|
# save original file
File.open(“C:/rubydev1/mail7/log/” +
base_part_of(attachment.original_filename)
,File::CREAT|File::TRUNC|File::WRONLY,0666){ |f|
f.write(attachment.read)
f.close()
}
end
end
And these code work fine, it did help me read the attachment file and
save it into the ruby directory. Then now i want to retrieve hte email
header such as the receiver, the senter, subject and date. It is
possible. Thanks
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.