Skip to content
  • Stuff
  • Travel
  • Beverages
  • Support Antipaucity
  • Projects
  • About

antipaucity

fighting the lack of good ideas

sending email in python with gmail

Posted on 15 May 201428 April 2014 By antipaucity

A Python nugget from Programming Your Home (review) I wanted to share from p97:

import smtplib
def send_email(subject, message)
    recipient = 'your_email_recipient@domain.tld'
    gmail_sender = 'your_gmail_account@gmail.com'
    gmail_password = 'your_gmail_password'

    #use tls
    gmail_smtp = smtplib.SMTP('smtp.gmail.com', 587)
    gmail_smtp.ehlo()
    gmail_smtp.starttls()
    gmail_smtp.ehlo()

    #login
    gmail_smtp.login(gmail_send, gmail_password)

    #message formatting
    mail_header = 'To: ' + recipient + '\n' + 'From: ' + gmail_sender + '\n' + 'Subject: ' + subject + '\n'
    message_body = message
    mail message = mail_header + '\n ' + message_body + '\n\n'

    #send
    gmail_smtp.sendmail(gmail_sender, recipient, mail_message)

    #close
    gmail_smtp.close()
code, quote, reprint, technical Tags:python, smtp

Post navigation

Previous Post: master the art of timing – law 35 – #48laws by robert greene
Next Post: a public – or white-labelable – rfe service a la uservoice, but easier to use

More Related Articles

new connexions collection available education
a new website news
automation commentary
nasa searching for new challenges hmmm
the ultimate measure of financial success finance
remembering sqrt technical
May 2014
S M T W T F S
 123
45678910
11121314151617
18192021222324
25262728293031
« Apr   Jun »
RSS Error: WP HTTP Error: cURL error 60: SSL: no alternative certificate subject name matches target hostname 'paragraph.cf'

Books

  • Debugging and Supporting Software Systems
  • Storage Series

External

  • Backblaze
  • Cirkul
  • Fundrise
  • Great Big Purple Sign
  • Password Generator
  • PayPal
  • Tech News Channel on Telegram
  • Vultr
  • Wish List

Other Blogs

  • Abiding in Hesed
  • Chris Agocs
  • Eric Hydrick
  • Jay Loden
  • Paragraph
  • skh:tec
  • Tech News Channel on Telegram
  • Veritas Equitas

Profiles

  • LinkedIn
  • Server Fault
  • Stack Overflow
  • Super User
  • Telegram
  • Twitter

Resume

  • LinkedIn
  • Resume (PDF)

Services

  • Datente
  • IP check
  • Password Generator
  • Tech News Channel on Telegram

Support

  • Backblaze
  • Built Bar
  • Cirkul
  • Donations
  • Fundrise
  • PayPal
  • Robinhood
  • Vultr
  • Wish List

35-questions 48laws adoption automation blog blogging books business career centos cloud community documentation email encryption facebook google history how-to hpsa ifttt linux money networking politics prediction proxy review scifi security social social-media splunk ssl startup storage sun-tzu tutorial twitter virtualization vmware wordpress work writing zombie

Copyright © 2025 antipaucity.

Powered by PressBook Green WordPress theme