I setup a standard rails mailer with multipart view following the official guide, like this:
mail(to: user.email, subject: "Welcome") do |format|
format.html { render layout: 'my_layout' }
format.text
end
With the clear and common intent to give priority to the html version of the message, only to find that, as this article points out, calling format.html
before the format.text
makes a lot of mail clients to show only the text version of the message. In my case I verified (and struggled with) that with both Gmail and Mozilla Thunderbird.
Is there a reliable solution to give precedence to the html version?
Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/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.
To preview it, create a file in test/previews and call the mailer method just as you would from any model or controller in your app. Then you can preview the email at [/rails/mailers/notification/welcome](http:// rails/mailers/notification/welcome).
The only solution I found so far is to switch format.html
with format.text
so that the text format is called before the html one. Which is exactly the opposite of what one would expect.
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