Created
October 31, 2014 15:52
-
-
Save jinhoyoo/bb61a040bcaff3e485bb to your computer and use it in GitHub Desktop.
Send e-mail on Gmail by python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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