9

我有的應該發送此文件中的一個的ActionMailer控制器:的ActionMailer沒有出現在文本郵件收發器空間

/user_mailer/welcome_email.text.erb 

這是文件的(樣品)含量:

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 

[編輯] 這是在控制器中的代碼:

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 

,這是在UserMailer 0的代碼的ActionMailer :: Base的

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

這是電子郵件我收到:

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

任何線索如何包含空格,回車和換行?

[編輯] 安裝letter_opener寶石後,我看到在我的控制檯如下:

----==_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 

我試圖改變「內容傳輸編碼」頭,但他們似乎並沒有改變。我也嘗試爲它設置一個默認值。它看起來像我們堅持使用7位編碼。

[編輯] 另外,應有助於我們找到問題是,我試圖通過以下PARAMS的郵件功能,以查看文件渲染器是否有問題:「Hellothere」

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

也出來整理。

然後,我試着下面的代碼,以確保它是否是導致錯誤的呈現或郵件功能。

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

也出來整理。

+0

源模板中的CRLF是什麼? –

+0

我不太確切,但我認爲如果我們解決空間問題並解決它,我們也將解決CRLF問題=) – Abdo

回答

0

這花了我一陣子來解決。 ActionMailer不是這個問題。

如果您遇到此問題,請首先確保它不是您的代碼或導致此問題的寶石。啓動一個新的rails應用程序並用它測試ActionMailer。 (感謝@RubyCyanide對此建議)

在我的情況下,這是一個函數join,我在我的String class初始值設定項中。您或您使用的寶石很可能與Mail的連接功能衝突。

希望這會有所幫助!

1

默認情況下,郵件程序應該發送文本電子郵件 - 這可能發生在客戶端。真正的解決方案是同時擁有文本和HTML模板(或者通過欺騙(或者僅僅是Markdown)爲兩者使用相同的模板,如果它們同樣簡單的話

+0

我確實有兩個,文本電子郵件正在呈現,我收到上面的電子郵件。我一次嘗試了1個文件,然後嘗試了兩個文件。我一直有同樣的問題。 – Abdo

+0

@Ado這仍然是可能的,這是一個客戶端問題,再加上我看不到你的HTML模板(像它實際上包含HTML)。 –

+0

同意戴夫在這裏,也許這是一個客戶端問題。 –

0

我會設置一個繼承自ActionMailer::Base的類然後在那裏創建你的welcome_email方法,然後在你的控制器調用FooMailer.welcome_email(@user.email).deliver。如果你這樣做很多,考慮將它移動到resque或延遲作業。 welcome_email.html.erb併發送出去?您可以在您的welcome_email方法中指定使用html(帶或不帶佈局),如下所示:

def welcome_email(user) 
    @user = user 
    @url = "http://znood.com/" 
    mail(:to => user.email, :subject => "Welcome to Znood!") do |format| 
    format.html #{ render :layout => 'my_layout' } 
    end 
end 

您可以觀看Ryan Bates RailsCast#206 here以查看正在使用的內容,同時他還展示了在發送郵件之前攔截郵件的方法,以便您看到它們的外觀。更簡單的方法是使用他的letter opener gem它在瀏覽器中打開電子郵件(在開發模式下使用)。

+0

對不起,編輯了代碼。這是我的。我嘗試了不同的格式,但沒有奏效。 – Abdo

+0

@Ado我還是把開封者的寶石放在適當的位置,看看你的應用發送了什麼,與你在客戶端看到的是什麼(gmail等)。也許這不是一個應用程序問題,而是一個客戶端配置問題。 –

+0

我安裝了開信刀寶石,得到了同樣的結果。所有的單詞整理到彼此。 – Abdo

相關問題