Reputation: 8392
I am using ActionMailer to send emails with rails with a third-party SMTP server, the email is always falling into the spam folder (when sending to gmail addresses), I contacted the support and they tested using mail-tester.com which indicates that there is the following issue:
Message only has text/html MIME parts
You should also include a text version of your message (text/plain)
In my mailer views I have only the html files, but when I look at Devise mailer I see that they have the same thing, there is not text version, so I am a little confused, what should I do in this case?
Upvotes: 0
Views: 1159
Reputation: 8392
I'm going to answer my answer as usual ;)
As best practice:
First: make sure your Html emails are wrapped in an html tag, or better use this:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<!-- your html email here -->
</body>
</html>
Second: in plus of your every html email file, add an equivalent file with .text.erb
extension, for example if you have a mailer file called reset_password.html.erb
then make sur you add another one reset_password.text.erb
that contains only plain text (No html tag ever!).
With that, if the receiver doesn't use HTML email, the text version of your email will be used.
Here is an example how to turn one of devise html template to plain text:
HTML version (confirmation_instructions.html.erb):
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
</body>
</html>
Text version (confirmation_instructions.text.erb):
Welcome <%= @email %>!
You can confirm your account email through the link below:
<%= confirmation_url(@resource, confirmation_token: @token) %>
Note also how I changed:
<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>
To:
<%= confirmation_url(@resource, confirmation_token: @token) %>
Because link_to will generate <a>
tag which we don't want to have in a text email.
Upvotes: 0