我在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
任何人都有解决方案。
感谢
不确定这是否有帮助,但我过去发送电子邮件的方式与略有不同
在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
在控制器中发送电子邮件
SubscriptionMailer.send_invoice(用户,pdf_path).交付
我不使用回形针,但这就是我在Rails2中发送附件的方式,作为的示例
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.root
在Rails 3和4中使用,对于Rails 2使用RAILS_ROOT
,看看这个问题:Rails根目录路径?