Skip to content

Instantly share code, notes, and snippets.

@jinhoyoo
Created October 31, 2014 15:52
Show Gist options
  • Save jinhoyoo/bb61a040bcaff3e485bb to your computer and use it in GitHub Desktop.
Save jinhoyoo/bb61a040bcaff3e485bb to your computer and use it in GitHub Desktop.
Send e-mail on Gmail by python
def send_email( gmail_user, gmail_pwd, mail_from, mail_to, title, message ):
import smtplib
# Prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (mail_from, ", ".join(mail_to), title, message)
try:
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(mail_from, mail_to, message)
#server.quit()
server.close()
print 'successfully sent the mail'
except:
print "failed to send mail"
if __name__ == "__main__":
send_email( 'g-mail account',
'password',
'from',
'to',
'title',
'message' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment