开发者

Can I look at Mailer views without actually sending an e-mail?

I think this may be a common situation… I'm working on a password recovery system for a Rails app that sends a link to the user to trigger a new password form. Pretty standard stuff.

On my development server I don't have any mail-sending software enabled 开发者_开发百科or configured (sendmail, SMTP settings, etc.) In config/environments/development.rb I have config.action_mailer.raise_delivery_errors = false to suppress any errors that arise since I don't have a local mail server enabled. This is all good and fine.

However, I would like to view the content of the e-mails while in production without actually sending the mail. I know that it's possible to kind of do this through testing, asserting that the sent (or faux-sent) mail has the correct content. Is there any way to reroute views or something, just temporarily in production, to view an HTTP-served version of the e-mail rather than blindly making assertions?


If you have a UserMailer setup with a "password_reminder" method, you can call create_password_reminder instead of deliver_password_reminder and it will create the message without actually sending. Then you could send the output to the log file:

Where you would have:

UserMailer.deliver_password_reminder

You can replace with:

logger.info UserMailer.create_password_reminder.encoded

Or if you want to send it to a file, you can do that as well.

That being said, the production environment really isn't the place for this sort of thing. I've never had a need to do this, because my mailers have full test coverage. I'd look into that option instead, but I gave the answer you asked for because I don't know your full situation. Happy coding :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜