I am working on e-mails for my rails app. Right now the only way I know to view the e-mail is to send it to myself. How do I get "daily_summary.html.haml", which is in the "notifications" folder under the "views" folder, to render in the browser? I was thinking I should just add the route:
match 'notifications' => 'notifications/daily_summary'
But then I don't know how to handle the controller/action side of things.
Action Mailer allows you to send emails from your application using mailer classes and views.
Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.
Since Rails 4.1, e-mail preview is native. All you need to do is create a class in this directory:
test/mailers/previews/
The class must extend ActionMailer::Preview
class WeeklyReportPreview < ActionMailer::Preview
def weekly_report
WeeklyReport.weekly_report(User.first)
end
end
Write methods that return Mail::Message
objects. They are accessible in the development environment using this url:
http://localhost:3000/rails/mailers/[preview_class_name]/[method_name]
In my case:
http://localhost:3000/rails/mailers/weekly_report/weekly_report
More info can be found in the ActionMailer API documentation
There's a gem called Letter Opener that sounds like it'll do exactly what you're looking for. It previews email messages in the browser rather than sending them. I haven't used it myself. If it works I'd love to hear about it, though!
https://github.com/ryanb/letter_opener
There's another one called Mail Viewer but it hasn't been actively developed in quite some time. Probably better to steer clear:
https://github.com/37signals/mail_view
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With