我在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
任何人都有解决方案。
由于
答案 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的用户(apache
,nginx
,www-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?