Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:23:28+00:00 2026-06-17T06:23:28+00:00

I have a rails app that sends out many notification e-mails. We have a

  • 0

I have a rails app that sends out many notification e-mails. We have a desire to let the user choose plain text vs html.

Initially our desire was always multipart so we didn’t set a content type and simplyhad both the email.html.erb & email.text.erb views, which would both get sent through and create a multipart.

However now when we specify the content_type based on the users preference a it does set itself properly to multipart or plain/text but the html template is included as plain text at the bottom of the plain text e-mail.

Here is the code:

Mailer Action:

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

The above code checks if the Clients company has html_emails is on, if so it set the content_type to plain/text. Which results in the following:

IRB output:

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

So far so good Multipart is false content_type is text/plain but then here is the resulting email body:

----==_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: <509fbfb7de92a_11e113fe8e4435b408399f@Jonathan.local.mail>

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: <509fbfb7e0496_11e113fe8e4435b40840ce@Jonathan.local.mail>

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

Why all the mime part data, why is the html content visible as text? I want a plain text only e-mail. Is this not how that is achieved?

One thing i noticed is that the html section of the e-mail says content_type: ‘text/html’. Maybe that is why it’s being included? Can this be prevented?

This question seemed to be close but seems this person was just trying to work out how to send multipart, which is not our issue:
Rails mailer mimepart visible as text in message body

i also tried changing our text template to email.text.plain.erb after seeing that in a few places but that did not work either.

Here are the email headers if anyone is curious:

    Delivered-To: jon@hivemindlabs.com
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: <info@hivemindlabs.com>
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 info@hivemindlabs.com 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 info@hivemindlabs.com designates 209.85.160.181 as permitted sender) smtp.mail=info@hivemindlabs.com
Received: by mail-gh0-f181.google.com with SMTP id z22so1332210ghb.26
    for <jon@hivemindlabs.com>; 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: <info@hivemindlabs.com>
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: info@hivemindlabs.com
To: jon@hivemindlabs.com
Message-ID: <509fbfb7e0c4e_11e113fe8e4435b4084183@Jonathan.local.mail>
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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:23:30+00:00Added an answer on June 17, 2026 at 6:23 am
    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
    

    Since the mailer action is called client_creation, this will render the template ‘client_creation.html.erb’ for the HTML part (if condition is true) and render the template ‘client_creation.text.erb’ for the text part. html_emails is a flag set by the company to enable/disable html email. For more info reference http://guides.rubyonrails.org/action_mailer_basics.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a client side app that sends out requests to a rails
Background: I've a rails app that sends out transactional and notification emails. 1/20 emails
I have a Rails app that sends a PDF to the user. I am
I have a Rails app that needs to send out emails with a particular
I have a Rails app that sends requests to a Node.js app. The node.js
I have a before_filter in my Rails app that sends users to login_url if
I have a Rails app that is served by Apache and Passenger, using only
I have a Rails app that does everything I need it to do via
I have a rails app that is using Devise perfectly in development. I have
I have a rails app that has asynchronous processing, and I'm having trouble getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.