Can I view Mailer views without actually sending email?

I think this may be a normal situation ... I am working on a password recovery system for a Rails application that sends a link to a user to launch a new password form. Pretty standard stuff.

On my development server, I do not have built-in or configured software for sending mail (sendmail, SMTP settings, etc.). In config/environments/development.rb , I have config.action_mailer.raise_delivery_errors = false to fix any errors that occur since I don't have the local mail server turned on. This is all good and beautiful.

However, I would like to view the contents of emails during production without actually sending mail. I know that it is possible to do this through testing, claiming that sent (or erroneous) mail has the correct content. Is there a way to redirect views or something else temporarily in production to view the HTTP version of the email, rather than blindly making claims?

+4
source share
1 answer

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

Where would you be:

 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 also do this.

So the work environment is really not the place for this kind of thing. I never had to do this because my email programs have full testing coverage. I would consider this option instead, but I gave the answer you asked because I do not know your complete situation. Happy coding :)

+1
source

Source: https://habr.com/ru/post/1299830/


All Articles