title: Reply to email using python 3.4
body: <p>I am trying to reply to an email using Python 3.4. The recipient of the email will be using Outlook (unfortunately) and it is important that Outlook recognizes the reply and displays the thread properly.</p>
  <p>The code I currently have is:</p>
  <pre class="lang-python prettyprint-override"><code>def send_mail_multi(headers, text, msgHtml=&quot;&quot;, orig=None):
      &quot;&quot;&quot;
      &quot;&quot;&quot;
  
      msg = MIMEMultipart('mixed')
      # Create message container - the correct MIME type is multipart/alternative.
      body = MIMEMultipart('alternative')
  
      for k,v in headers.items():
          if isinstance(v, list):
              v = ', '.join(v)
          msg.add_header(k, v)
  
      # Attach parts into message container.
      # According to RFC 2046, the last part of a multipart message, in this case
      # the HTML message, is best and preferred.
      body.attach(MIMEText(text, 'plain'))
      if msgHtml != &quot;&quot;: body.attach(MIMEText(msgHtml, 'html'))
      msg.attach(body)
  
      if orig is not None:
          msg.attach(MIMEMessage(get_reply_message(orig)))
          # Fix subject
          msg[&quot;Subject&quot;] = &quot;RE: &quot;+orig[&quot;Subject&quot;].replace(&quot;Re: &quot;, &quot;&quot;).replace(&quot;RE: &quot;, &quot;&quot;)
          msg['In-Reply-To'] = orig[&quot;Message-ID&quot;]
          msg['References'] = orig[&quot;Message-ID&quot;]+orig[&quot;References&quot;].strip()
          msg['Thread-Topic'] = orig[&quot;Thread-Topic&quot;]
          msg['Thread-Index'] = orig[&quot;Thread-Index&quot;]
      
      send_it(msg['From'], msg['To'], msg)
  </code></pre>
  <ul>
  <li>The function <code>get_reply_message</code> is removing any attachments as in <a href="https://stackoverflow.com/questions/2182196/how-do-i-reply-to-an-email-using-the-python-imaplib-and-include-the-original-mes" title="this answer">this answer</a>.</li>
  <li><code>send_it</code> function sets the Message-ID header and uses the proper SMTP configuration. Then it calls <code>smtplib.sendmail(fr, to, msg.as_string())</code></li>
  <li>Outlook receives the email but does not recognize/display the thread. However, the thread seems like being an attachment to the message (probably caused by <code> msg.attach(MIMEMessage(...))</code></li>
  </ul>
  <p>Any ideas on how to do this? Have I missed any headers?</p>