ruby-on-railsactionmailersparkpost

Rails content-type not staying set. SparkPost?


I am sending out an email with actionmailer through SparkPost. I have set the content-type the following ways:

in action model:

default content_type: 'text/html'

and in the model action:

headers['Content-Type'] = 'text/html'

I suspect that isn't the problem because when I send the email in development to mailcatcher it keeps the content-type and displays properly.

Even watching the production.log when it sends the email shows it sending it

Subject: Equipment Training for June
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

But when it arrives the message has been converted to:

Content-Type: text/plain;

I have tried receiving it with both gmail and office.com emails.

Almost forgot, for some reason it isn't happening on other mailers from the app which is why I initially thought it was a rails issue.


Solution

  • I figured it out, Sparkpost appears to convert html only emails to plain styling so that everyone will get it. I didn't have a .text.haml version of my mailer so it wasn't sending the email as a

    Content-Type: multipart/alternative
    

    Once I added that then Sparkpost would allow the multi-content to get through.