Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you send plaintext instead of HTML email from Rails?

I'd like to send plain text emails from a Rails app. In my mail sending config I have:

ActionMailer::Base.default_content_type = 'text/plain'

Nonetheless, when I send a test email from the Rails console, I get:

>> GeneralAppMailer.deliver_test

# ...

Content-Type: text/html; charset=utf-8

And looking at it in Gmail, it does seem to be handled as HTML.

like image 299
Ethan Avatar asked Jul 19 '09 20:07

Ethan


People also ask

How do I insert plain text into an HTML email?

I don't know how are you sending email from HTML, but all you have to do is to set header to Content-Type: text/plain;" instead of Content-Type: text/html;" . Then your email content will be sent as plain text without any parsing.

What is Action_ mailer in Rails?

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.

Are emails sent in plaintext?

A plain text email contains only text—no images, stylized fonts, or hyperlinks. Multi-part MIME (Multipurpose Internet Mail Extensions) bundles together a plain text version and an HTML version of the deployed email.


2 Answers

Be sure your template ends with .text.erb extension and not .html.erb. See ActionMailer documentation.

like image 69
Simone Carletti Avatar answered Oct 10 '22 05:10

Simone Carletti


Without seeing the test method in your GeneralAppMailer class, it's impossible to say, but it's probably because you're rendering an HTML-based view template to send the message. But maybe you should post your code.

like image 30
Jim Puls Avatar answered Oct 10 '22 05:10

Jim Puls