Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionMailer not showing spaces in text mailer

I have an ActionMailer controller that's supposed to send this file:

/user_mailer/welcome_email.text.erb

This is the (sample) content of the file:

Welcome to znood.com, <%= @user.name %>

You have successfully signed up to znood.com,
Your username is: <%= @user.email %>.

To login to the site, just follow this link: <%= @url %>.

Thanks for joining and have a great day!

The Znood Team

[edited] This is the code in the controller:

def sendmail
        @user = User.first
        UserMailer.welcome_email(@user).deliver
        render "user_mailer/welcome_email.text"
        #render the file to see what we're supposed to send
end

and this is the code in UserMailer < ActionMailer::Base

 def welcome_email(user)
    @user = user
    @url  = "http://znood.com/"
    mail(:to => user.email, :subject => "Welcome to Znood!") 
  end

This is the email I'm receiving:

Welcometoznood.com,AbdoAchkarYouhavesuccessfullysigneduptoznood.com,Yourusernameis:blabla.Tologintothesite,justfollowthislink:http://znood.com/.Thanksforjoiningandhaveagreatday!TheZnoodTeam

Any clue how to include the spaces, carriage returns and line feeds?

[edit] After installing the letter_opener gem, I see the following in my console:

----==_mimepart_4ea9882a2735c_1c782d964bc18193

Date: Thu, 27 Oct 2011 19:34:50 +0300

Mime-Version: 1.0

Content-Type: text/plain;

 charset=UTF-8

Content-Transfer-Encoding: 7bit

Content-ID: <[email protected]>



Welcometoznood.com,AbdoAchkarYouhavesuccessfullysigneduptoznood.com,Yourusername
is:blabla.Tologintothesite,justfollowthislink:http://znood.com/.Thanksforjoiningandhaveagreatday!TheZnoodTeam

I attempting changing the "Content-Transfer-Encoding" headers but they don't seem to change. I also tried setting a default value for it. It looks like we're stuck with 7bit encoding.

[Edited] Another that should help us find the problem is that I tried passing the following params to the mail function in order to see whether the file renderer is problematic:

   mail(:to => user.email, :subject => "Welcome to Znood!") do |format|
        #format.text(:content_transfer_encoding => "base64")
        format.text { render :text => "Hello there!" }
    end

"Hellothere!" also came out collated.

I then tried the code below to make sure whether it's the render or mail function that's causing the errors.

mail(:to => user.email, :subject => "Welcome to Znood!") do |format|
        format.text { "hello there!" }
end

Also came out collated.

like image 619
Abdo Avatar asked Oct 27 '11 15:10

Abdo


1 Answers

By default, the mailer should be sending text emails--it's possible this is happening on the client side. The real solution is to have both text and HTML templates (or, through trickery (or just Markdown), use the same template for both, if they're equally simple.

like image 191
Dave Newton Avatar answered Oct 31 '22 02:10

Dave Newton