Skip to content

Instantly share code, notes, and snippets.

@ygabo
Created August 10, 2013 09:00
Show Gist options
  • Save ygabo/6199683 to your computer and use it in GitHub Desktop.
Save ygabo/6199683 to your computer and use it in GitHub Desktop.
Send email.
def send_email():
import smtplib
gmail_user = "[email protected]"
gmail_pwd = "secret"
FROM = '[email protected]'
TO = ['[email protected]'] #must be a list
SUBJECT = "Testing sending using gmail"
TEXT = "Testing sending mail using gmail servers"
# Prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
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(FROM, TO, message)
#server.quit()
server.close()
print 'successfully sent the mail'
except:
print "failed to send mail"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment