我正在创建一个应用程序,将用于发送电子邮件。我不需要使用常规邮件和查看模板,因为我只需要接收将用于生成电子邮件的数据。但是,我认为使用ActionMailer
而不是直接与SMTP
交互有一些好处。我在尝试实例化ActionMailer::Base
的新实例时遇到问题。如何使用ActionMailer
而不必定义扩展ActionMailer::Base
的新类?
最佳答案
ActionMailer的底层功能由mail gem提供。这使您可以非常简单地发送邮件,例如:
Mail.deliver do
from '[email protected]'
to '[email protected]'
subject 'Here is the image you wanted'
body File.read('body.txt')
add_file :filename => 'somefile.png', :content => File.read('/somefile.png')
end
它支持与ActionMailer相同的方法交付。
关于ruby-on-rails - Rails:如何单独使用ActionMailer?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10391236/