0
votes

For rendering a text (not html) message with ActionMailer in Rails 3, I see many threads instructing the programmer to make a .text.erb file and run the following code:

mail do |format|
  format.html
  format.text
end

...but I wish to render a very short message, without using a mailer view at all. I have success doing this in html format but not in plain text.

I use the following code:

mail do |format|
  format.html{ render( text: 'my text' ) }
  format.text{ render( text: 'my text' ) }
end

...but it sends an html email every time. What can I do to send a plain-text email and specify its content without a mailer view file?

1

1 Answers

2
votes

From doc:

Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have welcome_email.text.erb and welcome_email.html.erb in app/views/user_mailer, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts.

Just do:

mail do |format|
  format.text{ render( text: 'my text' ) }
end

If you only want a text email.