ActionMailer and development mode, can it write to a file or something?

懵懂的女人 提交于 2019-12-04 15:38:54

问题


I want to test my registration process locally (development mode), how can I test how emails will be sent out and rendered etc?

I am not referring to a unit-test or integration test, but just while developing my app and going on the register page etc. I want it to send out the emails but to a file not using smtp.

Is this possible?

What options do I have?


回答1:


This is configurable in the config/environments/*.rb files.

# 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') }

Detailed information can be found in the config section of Action Mailer Basics or on ActionMailer::Base API


Rails 4.2 :file delivery method source and Mail::FileDelivery source




回答2:


LetterOpener makes it even simpler for you to preview the emails you just sent by opening the file in the browser automatically (in development environment of course).




回答3:


I realize you said you want to check emails in the context of manual testing, but it seems worth mentioning that these sorts of tests can be automated. email_spec is one gem i've used to do it.



来源:https://stackoverflow.com/questions/5286009/actionmailer-and-development-mode-can-it-write-to-a-file-or-something

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!