附件不发送导轨2的电子邮件

时间:2015-11-04 11:49:22

标签: ruby-on-rails ruby email email-attachments mailer

我在Rails 2 application工作,上传内容后发送电子邮件,image使用paperclip

Emails已成功解雇但我不想将图片附加到该电子邮件中,但我在电子邮件中尝试了很多not getting attachment

使用下面的代码:

#Call from model my opinion model
Mailer.deliver_new_my_opinion(self, self.user, email)

# Write in Mailer model

def new_my_opinion(my_opinion, user, email)

    @attachments   = File.read("#{Rails.root.to_s}"+"/public/system/attachment_images/744/original/map_screen.png")

    @subject      = "You have a new OPINION question"
    @from         = "#{Settings.site_name} <noreply@#{Settings.site_host}>"
    @recipients   = email
    @content_type = "multipart/mixed"
    @sent_on      = Time.now
    @body         = {:user => user, :my_opinion => my_opinion}
  end

任何人都有解决方案。

由于

2 个答案:

答案 0 :(得分:0)

不确定,如果这有帮助,但我曾经以稍微不同的方式发送电子邮件

在Mailer.rb

def send_invoice user, pdf_path
    attachments["invoice_#{Time.now.to_date}.pdf"] = File.read(pdf_path)
    @user = user
    mail(
        :to      => @user.email,
        :from    => "xxx@gmail.com",
        :subject => "xxx") do |format|
            format.html { render "send_invoice" }
        end
end

在Controller中发送电子邮件

SubscriptionMailer.send_invoice(user,pdf_path).deliver

答案 1 :(得分:0)

我不使用回形针,但这是我在Rails 2中发送附件的方式

attachment :content_type => "application/pdf",
  :body => File.read(RAILS_ROOT + '/pdfs/' + quote.id.to_s + '.pdf')

它可能是您正在使用的路径 - 运行Rails的用户(apachenginxwww-data等)可能没有正确的权限可以遍历目录从/home/开始,因此值得将其更改为

@attachments = File.read(RAILS_ROOT + "public/system/attachment_images/744/original/map_screen.png")

attachment = File.read(RAILS_ROOT + "public/system/attachment_images/744/original/map_screen.png")

修改

在Rails 3和4中使用了

Rails.root,对于Rails 2使用RAILS_ROOT,请看一下这个问题:Rails Root directory path?