title: Create Draft Email with Python's email.generator package
body: <p>I am currently using this code to generate an email with Python:</p>
  
  <pre class="lang-py prettyprint-override"><code>from email import generator
  from email.mime.multipart import MIMEMultipart
  from email.mime.text import MIMEText
  
  def Create_Email():
      msg            = MIMEMultipart('alternative')
      msg['Subject'] = 'My Subject'
      msg['To']      = 'test@gmail.com'
  
      html = """\
      &lt;html&gt;
          &lt;head&gt;&lt;/head&gt;
          &lt;body&gt;hello world&lt;/body&gt;
      &lt;/html&gt;"""
  
      part = MIMEText(html, 'html')
      msg.attach(part)
  
      outfile_name = r'C:\Downloads\email_sample.eml'
      with open(outfile_name, 'w') as outfile:
          gen = generator.Generator(outfile)
          gen.flatten(msg)
  
  Create_Email()
  </code></pre>
  
  <p>But when I then open the file with outlook, it appears as an <strong>already-sent</strong> email:<br></p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://i.stack.imgur.com/3p7V1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3p7V1.png" alt="enter image description here"></a></p>
  
  <p><strong>How can I change this so that the saved file will be treated as a <em>draft</em></strong>, which I can still edit and then send? Like so:<br></p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://i.stack.imgur.com/rPW7j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rPW7j.png" alt="enter image description here"></a></p>
  
  <p>If <code>email.generator</code> cannot do this, I'd be happy to use an alternative package.</p>