title: How to fix AttributeError: "NoneType" object has no attribute "encode" using smtplib
body: <p>I tried to make a script to allow a user to send the contents of a file via gmail.</p>
  
  <p>This is is my code:</p>
  
  <pre><code>if input1 == 'mail':
      path = input("open -- ")
      with open(path, "r") as file:
          addr = os.environ.get("email")
          pw = os.environ.get("pass")
          server = smtplib.SMTP("smtp.gmail.com", 587)
          server.ehlo()
          server.starttls()
          server.login(addr, pw)
          reading = file.read()
          subject = path
          body = reading
          msg = f'Subject {subject}\n\n{body}'
          input3 = ('recipient -- ')
          server.sendmail(email, input3, msg)'
  </code></pre>
  
  <p>and it's giving me this error:</p>
  
  <pre><code>  File "C:/Users/Whit/PycharmProjects/rps/venv/Scripts/maxnum.py", line 36, in &lt;module&gt;
      server.login(addr, pw)
    File "C:\Users\Whit\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 721, in login
      initial_response_ok=initial_response_ok)
    File "C:\Users\Whit\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 638, in auth
      authobject(challenge).encode('ascii'), eol='')
  AttributeError: 'NoneType' object has no attribute 'encode'
  </code></pre>