2012-11-11 44 views
5

मेरे पास एक रेल ऐप है जो कई अधिसूचना ई-मेल भेजता है। हमारे पास उपयोगकर्ता को सादे पाठ बनाम एचटीएमएल चुनने की इच्छा है।केवल सादा पाठ ई-मेल भेजना, रेल माइम भाग शरीर में शामिल है

प्रारंभ में हमारी इच्छा हमेशा मल्टीपार्ट थी इसलिए हमने सामग्री प्रकार सेट नहीं किया था और email.html.erb & ईमेल.text.erb दोनों दृश्यों को आसानी से हटा दिया था, जो दोनों एक मल्टीपार्ट के माध्यम से भेजे जाएंगे और बनाएंगे।

हालांकि अब जब हम उपयोगकर्ता वरीयता के आधार पर content_type निर्दिष्ट करते हैं तो यह मल्टीपार्ट या सादे/टेक्स्ट के लिए स्वयं को ठीक से सेट करता है लेकिन HTML टेम्पलेट को सादा पाठ ई-मेल के नीचे सादे पाठ के रूप में शामिल किया जाता है। इसलिए यदि यह सादा/पाठ को content_type सेट करते हैं तो ग्राहकों को कंपनी html_emails है, पर है

def client_creation(client) # When client checks in for the first time 
    @client = client 
    content_type = client.company.html_emails ? nil : 'text/plain' 
    email_prefix = client.company.brand ? client.company.brand.email_subject_prefix : 'MonitoringClient' 
    mail(to: @client.company.administrative_reporting_address, subject: "[#{email_prefix}][Initial Check-in] #{@client.machine_name.html_safe} of #{@client.clientgroup.name}", content_type: content_type) 
end 

ऊपर कोड चेक:

मेलर कार्रवाई:

यहाँ कोड है। जिसमें परिणाम निम्नलिखित:

आईआरबी उत्पादन:

----==_mimepart_509fbfb7ddb8b_11e113fe8e4435b4083853 
Date: Sun, 11 Nov 2012 09:09:43 -0600 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 
Content-ID: <[email protected]> 

First check-in notification for Jonathan. 

=========================== CLIENT DETAILS =========================== 
MACHINE INFORMATION: 
    MacBookAir4,1 

REPORT TIME: 
    Nov 11, 2012 8:17am 
CLIENT GROUP: 
    Hivemind Labs 
MACHINE NAME: 
    Jonathan 
LAST USER: 
    Jonathan 
SERIAL NUMBER: 
    ommited 


MACHINE SPECIFICATIONS: 
    RAM: 
    4 GB 
    PROCESSOR INFO: 
    1x 
    1.8 GHz, 
    2 core 
    Intel Core i7 
CLIENT VERSION: 
    5.0.5 
UPTIME AT LAST CHECKIN: 
    4 days, 21 hours, 11 mins 



----==_mimepart_509fbfb7ddb8b_11e113fe8e4435b4083853 
Date: Sun, 11 Nov 2012 09:09:43 -0600 
Mime-Version: 1.0 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 
Content-ID: <[email protected]> 

<!DOCTYPE html> 
<html> 
<head> 
<title> </title> 
</head> 
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0"> 
    <table style="box-shadow: 0px 0px 28px -10px #222; margin: 10px auto 20px" border="0" cellpadding="0" cellspacing="0" width="600" id="templateContainer" > 
    <tr> 
       <td align="center" valign="top"> 
        <table border="0" cellpadding="0" cellspacing="0" width="600" id="templateHeader"> 
         <tr> 
          <td class="headerContent"> 

          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
    <tr> 
       <td align="left" valign="top" style="width:600px"> 
        <table border="0" cellpadding="10" cellspacing="0" width="600px" id="templateBody"> 
         <tr> 
          <td valign="top" class="bodyContent"> 
           <table border="0" cellpadding="0" cellspacing="0" width="600px"> 
            <tr> 
             <td valign="top"> 
              <div class="mainContent"> 

<style type="text/css" media="screen"> 
    table.info tr td:first-child{ 
     width:40%; 
     color: #ffffff; 
     text-shadow:1px 1px 1px #555; 
     background-color: #2C2C2C; 
     background-image: -moz-linear-gradient(top, #888, #777); 
     background-image: -ms-linear-gradient(top, #888, #777); 
     background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#888), to(#777)); 
     background-image: -webkit-linear-gradient(top, #888, #777); 
     background-image: -o-linear-gradient(top, #888, #777); 
     background-image: linear-gradient(top, #888, #777); 
     background-repeat: repeat-x; 
     filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#888', endColorstr='#777', GradientType=0); 
     -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25),inset 0 -1px 0 rgba(0, 0, 0, 0.1); 
     -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25),inset 0 -1px 0 rgba(0, 0, 0, 0.1); 
     box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) 
     } 
     legend + .page-actions.page-actions-small { 
     margin-top: -49px; 
     } 
</style> 
    <legend>Client Details</legend> 
<div id="" class="page-actions page-actions-small pull-right"> 
    <a href="#" class="btn btn-mini">Complete Overview</a> 
</div> <!-- close: page-actions --> 
<table style="" class="table table-bordered table-striped table-condensed info"> 
    <tbody> 
    <tr><td>Client Group</td><td>Hivemind Labs</td></tr> 
    <tr><td>Serial Number</td><td></td></tr> 
    <tr><td>Machine Name</td><td> Jonathan</td></tr> 
    <tr><td>Last User</td><td>Jonathan</td></tr> 
    <tr><td>Operating system</td><td>OS X 10.8.2 (12C60)</td></tr> 
    <tr><td>Installed RAM</td><td>4 GB</td></tr> 
    <tr><td>Model Details</td><td>MacBookAir4,1</td></tr> 
    <tr><td>Uptime</td><td>4 days, 21 hours, 11 mins</td></tr> 
    </tbody> 
</table> 

               </div> 
             </td> 
            </tr> 
           </table> 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
      <tr> 
       <td align="center" valign="top"> 
        <table border="0" cellpadding="5" cellspacing="0" width="100%"> 
         <tr> 
          <td style="padding: 0 0 20px 20px"> 
           <small class="copyright"> All Rights Reserved.</small> 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
     </table> 
</body> 

</html> 



----==_mimepart_509fbfb7ddb8b_11e113fe8e4435b4083853-- 

क्यों सब:

#<Mail::Message:70269523266340, Multipart: false, Headers: <Date: Sun, 11 Nov 2012 09:09:43 -0600>, <From: [email protected]>, <To: ommitted>, <Message-ID: <[email protected]>>, <Subject: [Initial Check-in] Jonathan of hivemind labs>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>> 

अब तक तो अच्छा मल्टीपार्ट झूठी content_type पाठ/सादे है, लेकिन फिर यहाँ जिसके परिणामस्वरूप ईमेल शरीर है माइम भाग डेटा, HTML सामग्री टेक्स्ट के रूप में क्यों दिखाई दे रही है? मैं केवल एक सादा पाठ चाहता हूं ई-मेल। क्या यह नहीं है कि यह कैसे हासिल किया जाता है?

एक बात मैंने देखी है कि ई-मेल का HTML अनुभाग Content_type: 'text/html' कहता है। शायद यही कारण है कि इसे शामिल किया जा रहा है? क्या इसे रोका जा सकता है?

यह सवाल करीब लग रहा था लेकिन यह व्यक्ति सिर्फ बाहर काम करने के लिए कैसे बहुखण्डीय है, जो हमारे मुद्दा नहीं है भेजने के लिए कोशिश कर रहा था लगता है: Rails mailer mimepart visible as text in message body

मैं भी email.text.plain के लिए हमारी पाठ टेम्पलेट बदलते कोशिश की कुछ जगहों पर यह देखने के बाद .erb लेकिन यह भी काम नहीं किया।

यहाँ ईमेल हेडर हैं अगर कोई उत्सुक है:

Delivered-To: [email protected] 
Received: by 10.60.124.225 with SMTP id ml1csp294562oeb; 
    Sun, 11 Nov 2012 07:09:46 -0800 (PST) 
Received: by 10.236.122.143 with SMTP id t15mr16902572yhh.26.1352646586007; 
    Sun, 11 Nov 2012 07:09:46 -0800 (PST) 
Return-Path: <[email protected]> 
Received: from mail-gh0-f181.google.com (mail-gh0-f181.google.com [209.85.160.181]) 
    by mx.google.com with ESMTPS id p20si1615988ano.75.2012.11.11.07.09.45 
    (version=TLSv1/SSLv3 cipher=OTHER); 
    Sun, 11 Nov 2012 07:09:45 -0800 (PST) 
Received-SPF: pass (google.com: domain of [email protected] designates 209.85.160.181 as permitted sender) client-ip=209.85.160.181; 
Authentication-Results: mx.google.com; spf=pass (google.com: domain of [email protected] designates 209.85.160.181 as permitted sender) [email protected] 
Received: by mail-gh0-f181.google.com with SMTP id z22so1332210ghb.26 
    for <[email protected]>; Sun, 11 Nov 2012 07:09:45 -0800 (PST) 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; 
    d=google.com; s=20120113; 
    h=date:from:to:message-id:subject:mime-version:content-type 
    :content-transfer-encoding:x-gm-message-state; 
    bh=OFH7ScRSXxkeW0Ig+UdGXMRcNoKwEcIPDFaTVrwnnRs=; 
    b=i+Oq1YtnJVh3hM6bB5JgXbZGUS1KnvIsyX2zU2UCoCGtGd1DrvifYQGTPSkqbjlqg0 
    vArkYg9ZOApVkueLh8fU3lXocCgXy1cSQ7pnTDo5aj2YKyNj8XcshGU5PN24nKmNkJNn 
    AOHD75ounew3lrfL/dPGx5rfD6ROIgOORIHioPUSs9sFPUbbfu1OsPDBlAAv4zPWbBuG 
    tbjR1JL7DntD3sPzcHiZJ9XyajhhuYQPZ/j5f/++Bdyfqq1s8uxlZvapQlndai58KtqU 
    EjmDb91+C/uIc9FwcT2YE0vv3pdrIHnlGYmfyX/sB0ZDDET+dTFcCOmbqpbaAwxavRb+ 
    GAUg== 
Received: by 10.236.83.103 with SMTP id p67mr16870674yhe.78.1352646585386; 
    Sun, 11 Nov 2012 07:09:45 -0800 (PST) 
Return-Path: <[email protected]> 
Received: from gmail.com (ip-216-115-131-150.static.eatel.net. [216.115.131.150]) 
    by mx.google.com with ESMTPS id u11sm3665339ane.11.2012.11.11.07.09.44 
    (version=TLSv1/SSLv3 cipher=OTHER); 
    Sun, 11 Nov 2012 07:09:45 -0800 (PST) 
Date: Sun, 11 Nov 2012 09:09:43 -0600 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: [Initial Check-in] Jonathan of hivemind labs 
Mime-Version: 1.0 
Content-Type: text/plain; 
    charset=UTF-8 
Content-Transfer-Encoding: 7bit 
X-Gm-Message-State: ALoCoQlSNX58YFYU6Idzq84zch66CnL12QD/WrT3R8kcu0wT2jV9oppA1clUl9pHY2hta0vIMqJx 

उत्तर

7
mail(to: @client.company.administrative_reporting_address, 
    subject: "[#{email_prefix}][Initial Check-in] \ 
       #{@client.machine_name.html_safe} of #{@client.clientgroup.name}", 
    content_type: content_type) do |format| 
    format.html if client.company.html_emails 
    format.text 
end 
+0

मैं वास्तव में यह पता अपने आप को एक अलग पद्धति के माध्यम से काम किया था लेकिन पर्याप्त इस समान मैं इसे काम करना चाहिए विश्वास करते हैं। – JonathanSimmons