Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails ActionMailer adds carriage return (=0D) to end of every line in html

My ActionMailer adds a carrige return to the end of every line:

<!DOCTYPE html>=0D
<html>=0D
<head>=0D
...
this is stuff=0D
=0D
This intro has some content in it.=0D
=0D
blah.=0D
=0D

My mail is rendered perfectly fine in the preview host/rails/mailers/user_mailer/periodic_digest.html (and also in mailcatcher), but when I send the mail through Mailgun I end up getting double line spacing between my text.

In app/mailers/user_mailer.rb:periodic_digest

m = mail(from: 'blah', to: 'me')
puts m.html_part.body.decoded

I do get correctly formatted html.

How can I send out my html without the carriage return character =0D being appended to every line?

like image 249
Roman Avatar asked Oct 27 '25 08:10

Roman


1 Answers

This isn't an error on Rails' part. Mailgun just handles it in an undesirable manner.

Carriage returns are used to forcibly wrap lines in quoted printable encoded text. If you're sending multipart or plaintext email, RFC 5322 (and 2822 and 822 before it) specify that you must wrap lines at no more than 998 characters. For practical purposes, most email clients wrap closer to 70 characters.

In order to insert a visible newline, you need to use a carriage return followed by a linefeed, which you're probably accustomed to seeing represented as \r\n. This is in contrast to the typical unix-style line endings (just a linefeed) you would have in your code or text files.

like image 148
coreyward Avatar answered Oct 28 '25 21:10

coreyward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!