html – Rails邮件程序mimepart可见为邮件正文中的文本

前端之家收集整理的这篇文章主要介绍了html – Rails邮件程序mimepart可见为邮件正文中的文本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用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 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--

控制台的输出

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

解决方法

请勿指定:content_type =>邮件方法中的“text / html”.由于您使用的是格式块,因此rails会自动选择mime类型.

更多细节:

试试这个发送多部分电子邮件(即电子邮件的html和文本格式).注意格式的顺序.

mail(:to => "apoorvparijat@gmail.com",:subject => "html mailer") do |format|
    format.text { render :text => "bing" }
    format.html { render 'testing' }
end
原文链接:https://www.f2er.com/html/227133.html

猜你在找的HTML相关文章