title: How to send an email through gmail without enabling 'insecure access'?
body: <p>Google are pushing us to improve the security of script access to their gmail smtp servers.  I have no problem with that.  In fact I'm happy to help.</p>
  
  <p>But they're not making it easy.  It's all well and good to suggest we <code>Upgrade to a more secure app that uses the most up to date security measures</code>, but that doesn't help me work out how to upgrade bits of code that look like this:</p>
  
  <pre><code>server = smtplib.SMTP("smtp.gmail.com", 587)
  server.ehlo()
  server.starttls()
  server.login(GMAIL_USER, GMAIL_PASSWORD)
  server.sendmail(FROM, TO, MESSAGE)
  server.close()
  </code></pre>
  
  <p>Sure, I'll go and turn on "Access for less secure apps", but if anyone has worked out what to replace this code with, I'll be grateful.</p>