2012-10-30 9 views
6

Wysyłam pocztę testową za pomocą ActionMailer. Szablon jest renderowany, a poczta jest dostarczana w porządku. Jedyny problem to mimepart i inne dane nagłówka są wyświetlane przez Google w treści wiadomości.Rails mailer mimepart widoczny jako tekst w treści wiadomości

Oto kod, który maile ..

def testing 

    mail(:to => "[email protected]",:subject => "html mailer", :content_type => "text/html") do |format| 
      format.html { render 'testing' } 
      format.text { render :text => "bing" } 
    end 
end 

i tu jest e-mail odbierane.

----==_mimepart_508fd46252b8c_8023fe595835ad0479a6 Date: Tue, 30 Oct 2012 18:51:38 +0530  
Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 
Content-ID: <[email protected].local.mail> 
bing ----==_mimepart_508fd46252b8c_8023fe595835ad0479a6 Date: Tue, 30 Oct 2012 18:51:38 
+0530 Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 
7bit Content-ID: <[email protected] 
2.local.mail> Hi bing 
column 1 column 2 
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6-- 

Wyjście z konsoli -

Loading development environment (Rails 3.2.2) 
1.9.3-p125 :001 > RankMailer.testing.deliver 
I, [2012-10-30T18:51:38.331238 #2050] INFO -- : Rendered rank_mailer/testing.html.erb   
(1.8ms) 
I, [2012-10-30T18:51:38.333117 #2050] INFO -- : Rendered text template (0.0ms) 
I, [2012-10-30T18:51:45.824962 #2050] INFO -- : 
Sent mail to apoorvparij[email protected] (7484ms) 
D, [2012-10-30T18:51:45.825125 #2050] DEBUG -- : Date: Tue, 30 Oct 2012 18:51:38 +0530 
From: [email protected] 
To: [email protected] 
     Message-ID: <[email protected].local.mail> 
    Subject: html mailer 
    Mime-Version: 1.0 
    Content-Type: text/html; 
    charset=UTF-8 
    Content-Transfer-Encoding: 7bit 



    ----==_mimepart_508fd46252b8c_8023fe595835ad0479a6 
    Date: Tue, 30 Oct 2012 18:51:38 +0530 
    Mime-Version: 1.0 
    Content-Type: text/plain; 
    charset=UTF-8 
    Content-Transfer-Encoding: 7bit 
    Content-ID: <[email protected].local.mail> 

    bing 

    ----==_mimepart_508fd46252b8c_8023fe595835ad0479a6 
    Date: Tue, 30 Oct 2012 18:51:38 +0530 
    Mime-Version: 1.0 
    Content-Type: text/html; 
    charset=UTF-8 
    Content-Transfer-Encoding: 7bit 
    Content-ID: <[email protected].local.mail> 

    Hi bing 

    <table style="border:1px solid red"> 
     <tr> 
      <td>column 1</td> 
      <td>column 2</td> 
     </tr> 
    </table> 

    ----==_mimepart_508fd46252b8c_8023fe595835ad0479a6-- 

    => #<Mail::Message:70255316899740, Multipart: false, Headers: <Date: Tue, 30 Oct 2012 18:51:38 +0530>, <From: [email protected]>, <To: [email protected]>, <Message-ID: <[email protected].local.mail>>, <Subject: html mailer>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>> 

Odpowiedz

6

Nie określić :content_type => "text/html" w swoim sposobie mail. Ponieważ korzystasz z bloku formatowania, szyny automatycznie podniosą typ MIME.

Więcej szczegółów:

spróbować tego, aby wysłać e-mail (tj wieloczęściowy HTML i formatów tekstowych e-mail.). Zwróć uwagę na kolejność formatów.

mail(:to => "[email protected]", :subject => "html mailer") do |format| 
    format.text { render :text => "bing" } 
    format.html { render 'testing' } 
end 
+0

Problem polegał na tym, że ': content_type'. Usunąłem 'format.text' i opuściłem': content_type', tak jak jest. Wiadomość e-mail w formacie HTML jest wysyłana bez żadnego błędu. Chociaż mam jeszcze dowiedzieć się, co należy użyć ': content_type', jeśli muszę wysłać tekst zastępczy również w wiadomości e-mail. –

+0

Możesz używać wielu formatów. Następnie Mailer utworzy pocztę wieloczęściową z wszystkimi formatami użytkownika. Klient użytkownika lub interfejs internetowy wybierze odpowiedni format automatycznie. Aby użyć więcej formatów, usuń parametr ": content_type". Właśnie dodałem przykład do odpowiedzi. Zapoznaj się z tym [poradnikiem szyn] (http://guides.rubyonrails.org/action_mailer_basics.html#sending-multipart-emails), aby uzyskać więcej informacji i zamówić informacje. – rdamborsky

Powiązane problemy