rails - send emails, content, body ,attachment 附件

访问量: 684

refer to: https://api.rubyonrails.org/classes/ActionMailer/Base.html

class NotifierMailer < ApplicationMailer
  def welcome(recipient)
    attachments["free_book.pdf"] = File.read("path/to/file.pdf")
    mail(to: recipient,
         subject: "New account information",
         content_type: "text/html",
         body: "Hello there")
  end
endd

动态内容

https://stackoverflow.com/questions/18591126/rails-mailer-custom-dynamic-content

还是需要用view.  在view中, 使用 <%= raw @dynamic_content %> 即可。

然后在mailer 中, (忽略没写完的from)

使用附件

都是上面

订阅/RSS Feed

Subscribe