title: iPhone mail app shows my emails in plaintext by default
body: <p>I'm sending emails programmatically to users and I'm including both HTML and plaintext versions. In other iphone email clients I've tried HTML renders properly by default, however, the iphone's mail app decides to always render in plaintext. Other emails such as newsletters render properly in HTML by default in my iphone's mail app, so this makes me think that the problem comes from how I'm sending the email.</p>
  
  <p>Investigating this issue I decided to remove the plaintext part and send a few emails. After doing this the mail app did render the HTML by default. The problem is that I need to include the plaintext part in my emails, so removing it is not an option.</p>
  
  <p>To send the emails I'm using python 3.5's <strong>email</strong> and <strong>smtplib</strong> libraries. Here's the relevant pieces of code:</p>
  
  <pre><code>class GmailMailer(MailSender):
      def send_email(self):
          msg = self.prepare_email()
          with smtplib.SMTP(m_config['GMAIL_SMTP_ADDRESS'],
                            m_config['GMAIL_SMTP_PORT']) as smtpserver:
              smtpserver.ehlo()
              smtpserver.starttls()
              smtpserver.ehlo()
              smtpserver.login(m_config['GMAIL_USER_ADDRESS'], m_config['GMAIL_USER_PASSWORD'])
              smtpserver.send_message(msg, self.from_addr, self.to_addr)
              print('Email sent to: {0}, with address: {1}'.format(self.to_addr, self.from_addr))
          return msg.as_string()
  </code></pre>
  
  <p>The <strong>prepare_email</strong> is defined in the parent class and is defined as:</p>
  
  <pre><code>def prepare_email(self):
      msg = MIMEMultipart('alternative')
      msg['Subject'] = self.subject
      msg['From'] = self.from_addr
      msg['To'] = self.to_addr
      html_template = template_env.get_template('{0}.html'.format(self.template_name))
      text_template = template_env.get_template('{0}_text.html'.format(self.template_name))
      html_msg = html_template.render(self.context)
      text_msg = text_template.render(self.context)
      msg.attach(MIMEText(html_msg, 'html'))
      msg.attach(MIMEText(text_msg, 'text'))
      return msg
  </code></pre>
  
  <p>The actual text is generated from templates using Jinja2 with variables that are passed to the constructor and that are specific to each user. Since the procedure is straightforward and emails are rendered properly in both Gmail and Spark email clients, I assume that the problem is not generated by the rendering of the text/html by Jinja2.</p>