Rails邮件程序mimepart可在消息正文中显示为文本 [英] Rails mailer mimepart visible as text in message body
问题描述
我使用ActionMailer发送测试邮件。模板正在呈现,邮件正在正常传递。唯一的问题是Google在邮件正文中显示mimepart和其他标题数据。
以下是邮件的代码。
def testing
mail(:to =>apoorvparijat@gmail.com,:subject =>html mailer, :content_type =>text / html)do | format |
format.html {render'testing'}
format.text {render:text => bing}
end
end
以下是收到的电子邮件。
---- == _ mimepart_508fd46252b8c_8023fe595835ad0479a6日期:2012年10月30日星期二18:51:38 +0530
Mime -Version:1.0 Content-Type:text / plain; charset = UTF-8 Content-Transfer-Encoding:7bit
Content-ID:< 508fd46254ea7_8023fe595835ad0480b8@Apoorv-Parijats-MacBook-Pro-2.local.mail>
bing ---- == _ mimepart_508fd46252b8c_8023fe595835ad0479a6日期:2012年10月30日星期二18:51:38
+0530 Mime-Version:1.0内容类型:text / html; charset = UTF-8 Content-Transfer-Encoding:
7bit Content-ID:<508fd46256465_8023fe595835ad04819c @ Apoorv-Parijats-MacBook-Pro-
2.local.mail> hi bing
第1栏第2栏
---- == _ mimepart_508fd46252b8c_8023fe595835ad0479a6--
<
加载开发环境(Rails 3.2.2)
1.9.3-p125: 001> RankMailer.testing.deliver
I,[2012-10-30T18:51:38.331238#2050] INFO - :渲染的rank_mailer / testing.html.erb
(1.8ms)
I, [2012-10-30T18:51:38.333117#2050]信息 - :渲染文本模板(0.0ms)
I,[2012-10-30T18:51:45.824962#2050]信息 - :
发送邮件至apoorvparijat@gmail.com(7484ms)
D,[2012-10-30T18:51:45.825125#2050] DEBUG - :日期:2012年10月30日星期二18:51:38 +0530
来自:admin@rankdemon.com
致:apoorvparijat@gmail.com
消息ID:< 508fd462572ec_8023fe595835ad0482c0@Apoorv-Parijats-MacBook-Pro-2.local.mail>
主题:html邮件程序
Mime-Version:1.0
Content-Type:text / html;
charset = UTF-8
Content-Transfer-Encoding:7bit
---- == _ mimepart_508fd46252b8c_8023fe595835ad0479a6
日期:Tue ,2012年10月30日18:51:38 +0530
Mime-Version:1.0
Content-Type:text / plain;
charset = UTF-8
Content-Transfer-Encoding:7bit
Content-ID:< 508fd46254ea7_8023fe595835ad0480b8@Apoorv-Parijats-MacBook-Pro-2.local.mail>
bing
---- == _ mimepart_508fd46252b8c_8023fe595835ad0479a6
日期:2012年10月30日星期二18:51:38 +0530
Mime-Version: 1.0
Content-Type:text / html;
charset = UTF-8
Content-Transfer-Encoding:7bit
Content-ID:< 508fd46256465_8023fe595835ad04819c@Apoorv-Parijats-MacBook-Pro-2.local.mail>
喜bing
< table style =border:1px solid red>
< tr>
< td>第1列< / td>
< td>第2栏< / td>
< / tr>
< / table>
---- == _ mimepart_508fd46252b8c_8023fe595835ad0479a6--
=> #< Mail :: Message :: Message:70255316899740,Multipart:false,Headers:< Date:Tue,2012年10月30日18:51:38 + 0530>,< From:admin@rankdemon.com>,< To:apoorvparijat < Message-ID:< Message-ID:< 508fd462572ec_8023fe595835ad0482c0@Apoorv-Parijats-MacBook-Pro-2.local.mail>>,< Subject:html mailer>,< Mime-Version:1.0> ,< Content-Type:text / html>,< Content-Transfer-Encoding:7bit>>
不要指定: content_type => text / html
在你的邮件方法中。由于您使用的是格式块,因此rails会自动选取mime类型。
更多详情:
尝试发送多部分电子邮件(即HTML和文本格式的电子邮件)。注意格式的顺序。
mail(:to =>apoorvparijat@gmail.com,:subject => html邮件程序)do | format |
format.text {render:text => bing}
format.html {render'testing'}
end
I'm sending test mail using ActionMailer. The template is being rendered and mail is being delivered fine. The only problem is the mimepart and other header data is displayed by Google in message body.
Here is the code that mails..
def testing
mail(:to => "apoorvparijat@gmail.com",:subject => "html mailer", :content_type => "text/html") do |format|
format.html { render 'testing' }
format.text { render :text => "bing" }
end
end
and Here's the email received.
----==_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: <508fd46254ea7_8023fe595835ad0480b8@Apoorv-Parijats-MacBook-Pro-2.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: <508fd46256465_8023fe595835ad04819c@Apoorv-Parijats-MacBook-Pro-
2.local.mail> Hi bing
column 1 column 2
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6--
Output of the console -
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 apoorvparijat@gmail.com (7484ms)
D, [2012-10-30T18:51:45.825125 #2050] DEBUG -- : Date: Tue, 30 Oct 2012 18:51:38 +0530
From: admin@rankdemon.com
To: apoorvparijat@gmail.com
Message-ID: <508fd462572ec_8023fe595835ad0482c0@Apoorv-Parijats-MacBook-Pro-2.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: <508fd46254ea7_8023fe595835ad0480b8@Apoorv-Parijats-MacBook-Pro-2.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: <508fd46256465_8023fe595835ad04819c@Apoorv-Parijats-MacBook-Pro-2.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: admin@rankdemon.com>, <To: apoorvparijat@gmail.com>, <Message-ID: <508fd462572ec_8023fe595835ad0482c0@Apoorv-Parijats-MacBook-Pro-2.local.mail>>, <Subject: html mailer>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>
Don't specify :content_type => "text/html"
in your mail method. Since you're using format block, rails will automatically pick up mime type.
MORE DETAILS:
Try this to send out multipart email (ie. both html and text formats of email). Notice the order of formats.
mail(:to => "apoorvparijat@gmail.com", :subject => "html mailer") do |format|
format.text { render :text => "bing" }
format.html { render 'testing' }
end
这篇关于Rails邮件程序mimepart可在消息正文中显示为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!