ActionMailer和开发模式,它可以写入文件或其他东西吗?

Bla*_*man 22 ruby-on-rails actionmailer

我想在本地测试我的注册过程(开发模式),我如何测试如何发送和呈现电子邮件等?

我不是指单元测试或集成测试,而只是在开发我的应用程序并进入注册页面等时.我希望它发送电子邮件但发送到不使用smtp的文件.

这可能吗?

我有什么选择?

Hak*_*onB 45

这可以在config/environments/*.rb文件中配置.

# output to tmp/mails directory
config.action_mailer.delivery_method = :file
# ... and to specify output location
# config.action_mailer.file_settings = { :location => Rails.root.join('tmp/mail') }
Run Code Online (Sandbox Code Playgroud)

详细信息可以在发现配置部分动作梅勒基础上或的ActionMailer :: Base的API


Rails 4.2 :file 传递方法源Mail :: FileDelivery源

  • 不要忘记在进行配置更改后重新启动服务器.;) (7认同)

lul*_*ala 8

通过在浏览器中自动打开文件(当然在开发环境中),LetterOpener使您更简单地预览刚刚发送的电子邮件.

  • 适用于发送电子邮件的一次性测试,但我可能会推荐[mailcatcher](https://github.com/sj26/mailcatcher#rvm)进行长期测试 (2认同)