Rails - ActionMailer - How to send an attachment that you create?

后端 未结 2 850
春和景丽
春和景丽 2020-12-25 12:31

In rails3 w ActionMailer, I want to send a .txt file attachment. The challenge is this txt file does not exist but rather I want to create the txt file given a large block o

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 13:15

    First the method to send email

    class ApplicationMailer < ActionMailer::Base
       def welcome(user, filename, path)
          attachments[filename] = File.read(path)
          mail(:to => user.email, :subject => "New account information")
       end
    end
    

    Call the method with the params

    UserMailer.welcome(user, filename, path).deliver
    

提交回复
热议问题