title: Setting email content from string in email.message?
body: <p>I'd like to send an email using Python.</p>
  
  <p>There's sendmail (<a href="https://stackoverflow.com/questions/73781/sending-mail-via-sendmail-from-python">Sending mail via sendmail from python</a>), but also <a href="https://docs.python.org/3/library/smtplib.html" rel="nofollow noreferrer">https://docs.python.org/3/library/smtplib.html</a>.
  It recommends constructing a message based on <a href="https://docs.python.org/3/library/email.message.html" rel="nofollow noreferrer">https://docs.python.org/3/library/email.message.html</a> and has a few examples <a href="https://docs.python.org/3/library/email.examples.html#email-examples" rel="nofollow noreferrer">https://docs.python.org/3/library/email.examples.html#email-examples</a> which reads the message content from file:</p>
  
  <pre><code># Open the plain text file whose name is in textfile for reading.
  with open(textfile) as fp:
      # Create a text/plain message
      msg = EmailMessage()
      msg.set_content(fp.read())
  </code></pre>
  
  <p>I've tried</p>
  
  <pre><code>msg.set_content(b"test message sent locally")
  </code></pre>
  
  <p>but that results in <code>TypeError: set_bytes_content() missing 2 required positional arguments: 'maintype' and 'subtype'</code>. It seems <a href="https://docs.python.org/3/library/email.message.html#email.message.EmailMessage.set_content" rel="nofollow noreferrer">https://docs.python.org/3/library/email.message.html#email.message.EmailMessage.set_content</a> requires a context manager?</p>
  
  <p>How can a string be used to construct the message body?</p>