ruby-on-rails - 使用Rails接收电子邮件(ActionMailer)以处理图像附件

标签 ruby-on-rails email paperclip actionmailer

我正在尝试解析发送到我的应用服务器的电子邮件。
它应该阅读电子邮件以通过电子邮件找到用户,然后添加照片
用户的照片模型
这是我到目前为止所拥有的。我究竟做错了什么?

class Mailman < ActionMailer::Base 
  def receive(email) 
    logger.info("Got an email about: #{email.subject}") 
    if (@user = User.find_by_email(email.from)) 
      if email.has_attachments? 
        for attachment in email.attachments 
        #...@user.photos.create(:data_file_name => attachment.original_filename, 
        # :data_content_type => attachment.content_type, :data_file_size => attachment.size, 
        # :data_updated_at => Time.now.to_datetime) 
        # @user.photos << attachment 
        # I don't think this is the right way to do this... 
        end 
      end 
    else 
      logger.info("No user found with email: #{email.from}") 
    end 
  end 
end 

class User < ActiveRecord::Base 
  acts_as_authentic 
  has_attached_file :avatar 
  has_many :photos, :dependent => :destroy 
  accepts_nested_attributes_for :photos 
  # What does this do? 
end 


class Photo < ActiveRecord::Base 
  belongs_to :user 
  has_attached_file :data 
end 


class AddAttachmentsDataToPhoto < ActiveRecord::Migration 
  def self.up 
    add_column :photos, :data_file_name, :string 
    add_column :photos, :data_content_type, :string 
    add_column :photos, :data_file_size, :integer 
    add_column :photos, :data_updated_at, :datetime 
  end 
  def self.down 
    remove_column :photos, :data_file_name 
    remove_column :photos, :data_content_type 
    remove_column :photos, :data_file_size 
    remove_column :photos, :data_updated_at 
  end 
end

最佳答案

我知道这有点晚了,但是对于遇到此问题的其他人,我写了一篇博客文章解释了如何use paperclip to save attachments from incoming emails in Rails 3

关于ruby-on-rails - 使用Rails接收电子邮件(ActionMailer)以处理图像附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1795104/

相关文章:

regex - 从电子邮件地址中提取域名的一行代码

java - 如何将 javax.mail.Session setDebugOut 重定向到 log4j 记录器?

ruby-on-rails - 如何从 Paperclip 文件动态设置 preserve_files 选项?

ruby-on-rails - Rails 设计不发送确认电子邮件,但需要

ruby-on-rails - rails : include related object in JSON output

email - 释放 send-mailmessage 出错时留下的文件锁

ruby-on-rails - 了解 Paperclip 中的 id_partition

ruby-on-rails - 如果条件为真,则用回形针应用处理器

ruby-on-rails - 如何在 Ruby on Rails 中连接到 MySQL?

ruby-on-rails - Rails Heroku “The page you were looking for doesn’ t 存在。”部署后