goddamnyouryan
goddamnyouryan

Reputation: 6896

Rails 3.2 ActionMailer not rendering html in production

I have a production machine that is your basic CentOS machine on Amazon AWS, nothing special there.

I am essentially running this:

@digest = WeeklyDigest.most_recent.first
@mailer = DigestMailer.weekly_digest(@digest)
@mailchimp = MailChimp.new
@mailchimp.new_digest(@mailer.body.to_s)

What this code does is finds my latest weekly_digest, generate a new mailer using that, and then I grab the html from that and send it to mailchimp.

I have a weekly_digest.html.slim in app/views/digest_mailer and I have a digest_mailer.html.slim in app/views/layouts.

All of this works fine on development. @mailer returns this:

#<Mail::Message:70180219750380, Multipart: false, Headers: <From: [email protected]>, <To: [email protected]>, <Subject: Weekly Digest>, <Mime-Version: 1.0>, <Content-Type: text/html>>

When I run the exact same code on my AWS machine it returns:

#<Mail::Message:158221880, Multipart: false, Headers: <From: [email protected]>, <To: [email protected]>, <Subject: Weekly Digest>, <Mime-Version: 1.0>, <Content-Type: text/plain>>

The content type on dev is html and its text/plain on prod.

Any ideas about why this might happen? Something in the environment settings? I'm not finding much helpful in the docs.

Upvotes: 1

Views: 1914

Answers (1)

jshkol
jshkol

Reputation: 1877

Could be a discrepancy in default_content_type between your environment configurations. Try adding:

config.action_mailer.default_content_type = 'text/html'

To either your production.rb config file, or optionally your application.rb config file.

You should also check if a text template exists at app/views/digest_mailer/weekly_digest.text.erb and remove it since you're only trying to send HTML emails anyway.

Longterm you should consider sending multipart emails with both text and HTML. The Premailer Gem makes it really easy by automatically generating the text-part from the HTML template. That way you don't have to maintain both a text and HTML template and keep them in sync.

Upvotes: 3

Related Questions