To test emails in Rails, ActionMailer::Preview provides an easy way to preview emails in the browser. This feature is very useful for developers to test emails in the browser. However, to get a real sense of how an email will look in the inbox, it is necessary to download the email as an .eml file and open it in an email client. This was only possible by sending the email to a real email address (or using a service like MailCatcher, MailDev etc.) and downloading it from the inbox. This is not a very convenient way to test emails.
Let’s create a simple mailer and previewer.
Now let’s start the Rails server and navigate to the email previewer at http://localhost:3000/rails/mailers/custom_mailer/invite. We can see the email preview in the browser. However, there is no way to download the email as an .eml file from the preview.
Thanks to this PR, we can now download the email as an .eml file directly from the browser. This is enabled by default.
Here’s how it looks.