title: Send an email of my python output using python
body: <p>I am trying to send an email of my output using python. There are no errors in the code I wrote, and an email with no body is being sent. The email's body/context is completely blank. I was hoping that someone could assist me with this.</p>
  <pre><code>mail_content =[(print (&quot;------------------------------------------------&quot;)),
  print(&quot;this is a test2&quot;),
  print(&quot;Name=&quot;+x)]
  
  #The mail addresses and password
  sender_address = 'my internal server'
  receiver_address = 'example@example.com'
  #Setup the MIME
  message = MIMEMultipart()
  message['From'] = sender_address
  message['To'] = receiver_address
  message['Subject'] = 'A test mail sent by Python.'   #The subject line
  
  #Create SMTP session for sending the mail
  session = smtplib.SMTP('my internal server', 255) #my internal server with port
  session.starttls() #enable security
  text = message.as_string()
  session.sendmail(sender_address, receiver_address, text)
  session.quit()
  print('Mail Sent') 
  </code></pre>
  <p>If I add the following</p>
  <pre><code>#The body
  message.attach(MIMEText(mail_content, 'plain'))
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>    Traceback (most recent call last):
    File &quot;C:/Users/user1/Downloads/scripts.py&quot;, line 105, in &lt;module&gt;
      message.attach(MIMEText(mail_content, 'plain'))
    File &quot;C:\Program Files\Python\lib\email\mime\text.py&quot;, line 34, in __init__
      _text.encode('us-ascii')
  AttributeError: 'list' object has no attribute 'encode'
  </code></pre>